-
-
Notifications
You must be signed in to change notification settings - Fork 805
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consider offset, not index, when adjusting local variable table durin…
…g advice.
- Loading branch information
Showing
4 changed files
with
71 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
byte-buddy-dep/src/test/java/net/bytebuddy/asm/AdviceLocalVariableArrayTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package net.bytebuddy.asm; | ||
|
||
import net.bytebuddy.ByteBuddy; | ||
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy; | ||
import org.hamcrest.CoreMatchers; | ||
import org.junit.Test; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
|
||
import static net.bytebuddy.matcher.ElementMatchers.named; | ||
import static org.hamcrest.CoreMatchers.containsString; | ||
import static org.hamcrest.CoreMatchers.instanceOf; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.junit.Assert.fail; | ||
|
||
public class AdviceLocalVariableArrayTest { | ||
|
||
@Test | ||
public void testDebuggingSymbols() throws Exception { | ||
Class<?> type = new ByteBuddy() | ||
.redefine(Foo.class) | ||
.visit(Advice.to(ShiftVariablesAdvice.class).on(named("method"))) | ||
.make() | ||
.load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER_PERSISTENT) | ||
.getLoaded(); | ||
try { | ||
type.getMethod("method", long.class, Void.class, Void.class).invoke(type.getConstructor().newInstance(), | ||
0L, | ||
null, | ||
null); | ||
fail(); | ||
} catch (InvocationTargetException exception) { | ||
assertThat(exception.getTargetException(), instanceOf(NullPointerException.class)); | ||
String message = exception.getTargetException().getMessage(); | ||
if (message != null) { | ||
assertThat(message, containsString("\"b\"")); | ||
} | ||
} | ||
} | ||
|
||
public static class Foo { | ||
|
||
@SuppressWarnings("unused") | ||
public void method(long a, Void b, Void c) { | ||
b.hashCode(); | ||
} | ||
} | ||
|
||
public static class ShiftVariablesAdvice { | ||
|
||
static void enter(@Advice.Argument(1) Void ignored) { | ||
/* empty */ | ||
} | ||
|
||
static void exit(@Advice.Argument(1) Void ignored) { | ||
/* empty */ | ||
} | ||
} | ||
} |