Skip to content

Commit

Permalink
Enable injection into locally generated lambda methods - fixes BYTEMA…
Browse files Browse the repository at this point in the history
…N-416
  • Loading branch information
adinn committed Aug 2, 2021
1 parent 803afcf commit 615bb56
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
17 changes: 17 additions & 0 deletions agent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,23 @@
-Dorg.jboss.byteman.compile.to.bytecode so we also test the rules when compiled
-->
<executions>
<!-- lambda injection -->
<execution>
<id>bugfixes.TestLambdaInjection</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<forkCount>1</forkCount>
<reuseForks>true</reuseForks>
<includes>
<include>org/jboss/byteman/tests/bugfixes/TestLambdaInjection.class</include>
</includes>
<argLine>${debug.args} -javaagent:${project.build.directory}/byteman-agent-${project.version}.jar=script:${project.build.testOutputDirectory}/scripts/bugfixes/TestLambdaInjection.btm</argLine>
</configuration>
</execution>
<!-- java language operations -->
<execution>
<id>javaops.TestArithmetic</id>
Expand Down
26 changes: 23 additions & 3 deletions agent/src/main/java/org/jboss/byteman/agent/TransformContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,24 @@ public void recordFailedTransform(Throwable th)
public boolean matchTargetMethod(int access, String name, String desc)
{
// check the method is one we are really targeting
if ((access & (Opcodes.ACC_NATIVE|Opcodes.ACC_ABSTRACT|Opcodes.ACC_SYNTHETIC)) != 0 ||
!targetMethodName.equals(name) ||
(!targetDescriptor.equals("") && !TypeHelper.equalDescriptors(targetDescriptor, desc))) {

// cannot inject into a native or abstract method
if ((access & (Opcodes.ACC_NATIVE|Opcodes.ACC_ABSTRACT)) != 0) {
return false;
}

// cannot inject into a synthetic method unless it is a local lambda method
if ((access & Opcodes.ACC_SYNTHETIC) != 0 && !name.startsWith(LAMBDA_PREFIX)) {
return false;
}

// cannot inject unless the method name matches the target name
if (!targetMethodName.equals(name)) {
return false;
}

// cannot inject if there is a target descriptor which fails to match the actual descriptor
if (!targetDescriptor.equals("") && !TypeHelper.equalDescriptors(targetDescriptor, desc)) {
return false;
}

Expand Down Expand Up @@ -404,6 +419,11 @@ private String getKeyTriggerMethodDescriptor(String key)
*/
private static final String JAVA_METHOD_SPEC_PATTERN = "[A-Za-z0-9$.]+ +[A-Za-z0-9$]+\\(.*\\)";

/**
* The prefix that identifies a method generated to implement a local lambda expression."
*/
private static final String LAMBDA_PREFIX = "lambda$";

/**
* detect a method specification which includes a return type preceding the method name and transform
* it so that the return type is at the end.
Expand Down

0 comments on commit 615bb56

Please sign in to comment.