Skip to content

Commit

Permalink
Throw exception if local advice parameters are used without exit advi…
Browse files Browse the repository at this point in the history
…ce what is not currently supported.
  • Loading branch information
raphw committed Nov 28, 2019
1 parent 7af09d4 commit 9282054
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java
Original file line number Diff line number Diff line change
Expand Up @@ -5160,6 +5160,9 @@ protected static ForInstrumentedMethod of(TypeDescription instrumentedType,
if ((writerFlags & ClassWriter.COMPUTE_FRAMES) != 0 || classFileVersion.isLessThan(ClassFileVersion.JAVA_V6)) {
return NoOp.INSTANCE;
} else if (!exitAdvice) {
if (!initialTypes.isEmpty()) {
throw new IllegalStateException("Local parameters are not supported if no exit advice is present");
}
return new Trivial(instrumentedType, instrumentedMethod, (readerFlags & ClassReader.EXPAND_FRAMES) != 0);
} else if (copyArguments) {
return new WithPreservedArguments.UsingArgumentCopy(instrumentedType,
Expand Down
16 changes: 16 additions & 0 deletions byte-buddy-dep/src/test/java/net/bytebuddy/asm/AdviceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1746,6 +1746,14 @@ public void testInvisibleDelegationAdvice() throws Exception {
.make();
}

@Test(expected = IllegalStateException.class)
public void testLocalParameterWithoutExitIsIllegal() throws Exception {
new ByteBuddy()
.redefine(Sample.class)
.visit(Advice.to(EnterLocalVariableNotAllowedAdvice.class).on(named(FOO)))
.make();
}

@Test(expected = IllegalStateException.class)
public void testNonResolvedAdvice() throws Exception {
Advice.to(TypeDescription.ForLoadedType.of(TrivialAdvice.class));
Expand Down Expand Up @@ -3309,4 +3317,12 @@ public static void advice() {
}
}
}

public static class EnterLocalVariableNotAllowedAdvice {

@Advice.OnMethodEnter
public static void advice(@Advice.Local("foo") Void argument) {
/* empty */
}
}
}

0 comments on commit 9282054

Please sign in to comment.