Skip to content

Commit

Permalink
Add tests for skipping.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Mar 13, 2023
1 parent 8f68b03 commit 8e6f438
Show file tree
Hide file tree
Showing 3 changed files with 863 additions and 103 deletions.
6 changes: 4 additions & 2 deletions byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java
Original file line number Diff line number Diff line change
Expand Up @@ -12183,7 +12183,8 @@ public void visitEnd() {

/**
* Indicates that the value to be used for {@link OnMethodEnter#skipOn()} should be read from an array that is returned by
* the advice method, if the assigned property is non-negative.
* the advice method, if the assigned property is non-negative. If the returned array is shorter than the supplied index,
* an {@link ArrayIndexOutOfBoundsException} will be thrown, even if suppression is used.
*
* @return The array index for the value to be considered for skipping a method, or a negative value for using the returned value.
*/
Expand Down Expand Up @@ -12266,7 +12267,8 @@ public void visitEnd() {

/**
* Indicates that the value to be used for {@link OnMethodExit#repeatOn()} should be read from an array that is returned by
* the advice method, if the assigned property is non-negative.
* the advice method, if the assigned property is non-negative. If the returned array is shorter than the supplied index,
* an {@link ArrayIndexOutOfBoundsException} will be thrown, even if suppression is used.
*
* @return The array index for the value to be considered for repeating a method, or a negative value for using the returned value.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ public static Collection<Object[]> data() {
{FloatArrayAdvice.class, 0f},
{DoubleArrayAdvice.class, 0d},
{ReferenceArrayAdvice.class, null},
{BooleanArrayNoSkipAdvice.class, true},
{ByteArrayNoSkipAdvice.class, (byte) BAR},
{ShortArrayNoSkipAdvice.class, (short) BAR},
{CharacterArrayNoSkipAdvice.class, (char) BAR},
{IntegerArrayNoSkipAdvice.class, BAR},
{LongArrayNoSkipAdvice.class, (long) BAR},
{FloatArrayNoSkipAdvice.class, (float) BAR},
{DoubleArrayNoSkipAdvice.class, (double) BAR},
{ReferenceArrayNoSkipAdvice.class, FOO},
{BooleanArrayNullAdvice.class, true},
{ByteArrayNullAdvice.class, (byte) BAR},
{ShortArrayNullAdvice.class, (short) BAR},
Expand Down Expand Up @@ -1636,6 +1645,186 @@ private static void exit(@Advice.Return Object value) {
}
}

@SuppressWarnings("unused")
public static class BooleanArrayNoSkipAdvice {

public boolean foo() {
return true;
}

@Advice.OnMethodEnter(skipOn = Advice.OnDefaultValue.class, skipOnIndex = 0)
private static boolean[] enter() {
return new boolean[]{true};
}

@Advice.OnMethodExit
private static void exit(@Advice.Return boolean value) {
if (!value) {
throw new AssertionError();
}
}
}

@SuppressWarnings("unused")
public static class ByteArrayNoSkipAdvice {

public byte foo() {
return BAR;
}

@Advice.OnMethodEnter(skipOn = Advice.OnDefaultValue.class, skipOnIndex = 0)
private static byte[] enter() {
return new byte[]{BAR};
}

@Advice.OnMethodExit
private static void exit(@Advice.Return byte value) {
if (value != BAR) {
throw new AssertionError();
}
}
}

@SuppressWarnings("unused")
public static class ShortArrayNoSkipAdvice {

public short foo() {
return BAR;
}

@Advice.OnMethodEnter(skipOn = Advice.OnDefaultValue.class, skipOnIndex = 0)
private static short[] enter() {
return new short[]{BAR};
}

@Advice.OnMethodExit
private static void exit(@Advice.Return short value) {
if (value != BAR) {
throw new AssertionError();
}
}
}

@SuppressWarnings("unused")
public static class CharacterArrayNoSkipAdvice {

public char foo() {
return BAR;
}

@Advice.OnMethodEnter(skipOn = Advice.OnDefaultValue.class, skipOnIndex = 0)
private static char[] enter() {
return new char[]{BAR};
}

@Advice.OnMethodExit
private static void exit(@Advice.Return char value) {
if (value != BAR) {
throw new AssertionError();
}
}
}

@SuppressWarnings("unused")
public static class IntegerArrayNoSkipAdvice {

public int foo() {
return BAR;
}

@Advice.OnMethodEnter(skipOn = Advice.OnDefaultValue.class, skipOnIndex = 0)
private static int[] enter() {
return new int[]{BAR};
}

@Advice.OnMethodExit
private static void exit(@Advice.Return int value) {
if (value != BAR) {
throw new AssertionError();
}
}
}

@SuppressWarnings("unused")
public static class LongArrayNoSkipAdvice {

public long foo() {
return BAR;
}

@Advice.OnMethodEnter(skipOn = Advice.OnDefaultValue.class, skipOnIndex = 0)
private static long[] enter() {
return new long[]{BAR};
}

@Advice.OnMethodExit
private static void exit(@Advice.Return long value) {
if (value != BAR) {
throw new AssertionError();
}
}
}

@SuppressWarnings("unused")
public static class FloatArrayNoSkipAdvice {

public float foo() {
return BAR;
}

@Advice.OnMethodEnter(skipOn = Advice.OnDefaultValue.class, skipOnIndex = 0)
private static float[] enter() {
return new float[]{BAR};
}

@Advice.OnMethodExit
private static void exit(@Advice.Return float value) {
if (value != BAR) {
throw new AssertionError();
}
}
}

@SuppressWarnings("unused")
public static class DoubleArrayNoSkipAdvice {

public double foo() {
return BAR;
}

@Advice.OnMethodEnter(skipOn = Advice.OnDefaultValue.class, skipOnIndex = 0)
private static double[] enter() {
return new double[]{BAR};
}

@Advice.OnMethodExit
private static void exit(@Advice.Return double value) {
if (value != (double) BAR) {
throw new AssertionError();
}
}
}

@SuppressWarnings("unused")
public static class ReferenceArrayNoSkipAdvice {

public Object foo() {
return FOO;
}

@Advice.OnMethodEnter(skipOn = Advice.OnDefaultValue.class, skipOnIndex = 0)
private static Object[] enter() {
return new Object[]{FOO};
}

@Advice.OnMethodExit
private static void exit(@Advice.Return Object value) {
if (value == null) {
throw new AssertionError();
}
}
}

@SuppressWarnings("unused")
public static class BooleanArrayNullAdvice {

Expand Down
Loading

0 comments on commit 8e6f438

Please sign in to comment.