Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- master
pull_request:
workflow_dispatch:
inputs:
release_version:
Expand Down Expand Up @@ -54,6 +55,7 @@ jobs:

release:
needs: ["build-java"]
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/w/core/compiler/WCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import w.Global;
import w.util.IOUtils;

import java.io.InputStream;
import java.util.ArrayList;
Expand Down Expand Up @@ -163,7 +164,7 @@ private static List<String> findReferencedNestedClasses(String pureClassName, St
if (inputStream == null) {
return nested;
}
byte[] bytes = inputStream.readAllBytes();
byte[] bytes = IOUtils.readAllBytes(inputStream);
new ClassReader(bytes).accept(new ClassVisitor(Opcodes.ASM9) {
@Override
public MethodVisitor visitMethod(int access, String name, String descriptor,
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/w/core/model/ChangeResultTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.objectweb.asm.tree.VarInsnNode;
import w.Global;
import w.core.compiler.WCompiler;
import w.util.IOUtils;
import w.core.constant.Codes;
import w.web.message.ChangeResultMessage;

Expand Down Expand Up @@ -244,7 +245,7 @@ private byte[] readClassBytes(ClassLoader loader, String className) {
if (inputStream == null) {
return null;
}
return inputStream.readAllBytes();
return IOUtils.readAllBytes(inputStream);
} catch (Throwable e) {
Global.debug("change result read class bytes error: " + className + ", " + e.getMessage());
return null;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/w/core/model/OuterWatchTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import w.core.asm.WAdviceAdapter;
import w.core.diagnostic.DiagnosticRuntime;
import w.core.diagnostic.OuterWatchConfig;
import w.util.IOUtils;
import w.web.message.OuterWatchMessage;

import java.io.InputStream;
Expand Down Expand Up @@ -227,7 +228,7 @@ private byte[] readClassBytes(ClassLoader loader, String className) {
if (inputStream == null) {
return null;
}
return inputStream.readAllBytes();
return IOUtils.readAllBytes(inputStream);
} catch (Throwable e) {
Global.debug("outer watch read class bytes error: " + className + ", " + e.getMessage());
return null;
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/w/util/IOUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package w.util;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

public final class IOUtils {
private IOUtils() {
}

public static byte[] readAllBytes(InputStream inputStream) throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
byte[] data = new byte[8192];
int n;
while ((n = inputStream.read(data)) != -1) {
buffer.write(data, 0, n);
}
return buffer.toByteArray();
}
}
2 changes: 1 addition & 1 deletion src/test/java/w/core/ChangeResultTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public void asmShouldFailWhenNoMatchingInnerCall() throws IOException, Interrupt

SwapResult result = swapper.swap(msg);
Assertions.assertFalse(result.isSuccess());
Assertions.assertTrue(String.valueOf(result.getMessage()).contains("nothing was enhanced"));
Assertions.assertTrue(String.valueOf(result.getMessage()).contains("noSuchMethod"));
}

@Test
Expand Down
13 changes: 9 additions & 4 deletions src/test/java/w/core/OuterWatchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,13 @@ public void includeNestedShouldCollectRecursiveLambdaTargets() {
Map<String, Set<String>> targetMethods = transformer.getTargetMethods();

Set<String> methods = targetMethods.get("w.core.ChangeTarget");
long nestedLambdaCount = methods.stream()
.filter(method -> method.startsWith("lambda$outerWatchNestedLambdaTest$"))
// javac names the outer lambda lambda$<method>$N and, depending on the
// compiler version, the inner nested lambda either lambda$<method>$N or
// lambda$null$N, so count all collected lambda methods instead of one prefix.
long lambdaMethodCount = methods.stream()
.filter(method -> method.startsWith("lambda$"))
.count();
Assertions.assertEquals(2, nestedLambdaCount);
Assertions.assertEquals(2, lambdaMethodCount);
}

@Test
Expand Down Expand Up @@ -415,10 +418,12 @@ public void outerWatchResultShouldReportReadableLambdaOuterDisplay() {
Assertions.assertEquals("outerWatchNestedLambdaTest", changeTarget.outerWatchNestedLambdaTest());

OuterWatchResult result = (OuterWatchResult) swapResult.getData();
// JDK 8 names the inner nested lambda lambda$null$N, JDK 17 uses
// lambda$<method>$N; both must map to a readable [lambda$N] display.
Assertions.assertTrue(result.getInspectedCalls().stream()
.map(OuterWatchResult.InspectedCall::getOuterDisplay)
.anyMatch(display -> display != null
&& display.matches("w\\.core\\.ChangeTarget#outerWatchNestedLambdaTest\\[lambda\\$\\d+\\]")));
&& display.matches("w\\.core\\.ChangeTarget#[^\\[\\]]+\\[lambda\\$\\d+\\]")));
}

@Test
Expand Down
Loading