Skip to content

Commit

Permalink
Fixed serializable target.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Nov 16, 2016
1 parent e0fb95d commit c4bf7db
Show file tree
Hide file tree
Showing 8 changed files with 379 additions and 317 deletions.
Expand Up @@ -4294,12 +4294,9 @@ protected void apply(Instrumentation instrumentation,
redefinitionListener.onBatch(index, types, this.types);
try {
doApply(instrumentation, circularityLock, types, locationStrategy, listener);
} catch (UnmodifiableClassException exception) {
redefinitionListener.onError(index, types, exception, this.types);
failures.put(types, exception);
} catch (ClassNotFoundException exception) {
redefinitionListener.onError(index, types, exception, this.types);
failures.put(types, exception);
} catch (Throwable throwable) {
redefinitionListener.onError(index, types, throwable, this.types);
failures.put(types, throwable);
}
index += 1;
}
Expand Down Expand Up @@ -4354,16 +4351,20 @@ protected void doApply(Instrumentation instrumentation,
List<ClassDefinition> classDefinitions = new ArrayList<ClassDefinition>(types.size());
for (Class<?> type : types) {
try {
classDefinitions.add(new ClassDefinition(type, locationStrategy.classFileLocator(type.getClassLoader(), JavaModule.ofType(type))
.locate(TypeDescription.ForLoadedType.getName(type))
.resolve()));
} catch (Throwable throwable) {
JavaModule module = JavaModule.ofType(type);
try {
listener.onError(TypeDescription.ForLoadedType.getName(type), type.getClassLoader(), module, throwable);
} finally {
listener.onComplete(TypeDescription.ForLoadedType.getName(type), type.getClassLoader(), module);
classDefinitions.add(new ClassDefinition(type, locationStrategy.classFileLocator(type.getClassLoader(), JavaModule.ofType(type))
.locate(TypeDescription.ForLoadedType.getName(type))
.resolve()));
} catch (Throwable throwable) {
JavaModule module = JavaModule.ofType(type);
try {
listener.onError(TypeDescription.ForLoadedType.getName(type), type.getClassLoader(), module, throwable);
} finally {
listener.onComplete(TypeDescription.ForLoadedType.getName(type), type.getClassLoader(), module);
}
}
} catch (Throwable ignored) {
/* do nothing */
}
}
if (!classDefinitions.isEmpty()) {
Expand Down
420 changes: 245 additions & 175 deletions byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java

Large diffs are not rendered by default.

Expand Up @@ -18,15 +18,15 @@ public class AdviceAnnotationTest {
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
{Advice.Argument.class, ElementType.PARAMETER},
{Advice.BoxedArguments.class, ElementType.PARAMETER},
{Advice.BoxedReturn.class, ElementType.PARAMETER},
{Advice.AllArguments.class, ElementType.PARAMETER},
{Advice.FieldValue.class, ElementType.PARAMETER},
{Advice.Enter.class, ElementType.PARAMETER},
{Advice.Unused.class, ElementType.PARAMETER},
{Advice.Origin.class, ElementType.PARAMETER},
{Advice.Return.class, ElementType.PARAMETER},
{Advice.This.class, ElementType.PARAMETER},
{Advice.Thrown.class, ElementType.PARAMETER},
{Advice.StubValue.class, ElementType.PARAMETER},
{Advice.OnMethodEnter.class, ElementType.METHOD},
{Advice.OnMethodExit.class, ElementType.METHOD}
});
Expand Down
Expand Up @@ -2,7 +2,7 @@

import net.bytebuddy.ByteBuddy;
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
import net.bytebuddy.test.utility.DebuggingWrapper;
import net.bytebuddy.implementation.bytecode.assign.Assigner;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
Expand Down Expand Up @@ -72,7 +72,7 @@ public void foo() {
}

@Advice.OnMethodEnter
private static void enter(@Advice.BoxedArguments(readOnly = false) Object[] value) {
private static void enter(@Advice.AllArguments(readOnly = false, typing = Assigner.Typing.DYNAMIC) Object[] value) {
value = new Object[0];
}
}
Expand All @@ -85,7 +85,7 @@ public boolean foo(boolean value) {
}

@Advice.OnMethodEnter
private static void enter(@Advice.BoxedArguments(readOnly = false) Object[] value) {
private static void enter(@Advice.AllArguments(readOnly = false, typing = Assigner.Typing.DYNAMIC) Object[] value) {
value = new Object[]{true};
}
}
Expand All @@ -98,7 +98,7 @@ public byte foo(byte value) {
}

@Advice.OnMethodEnter
private static void enter(@Advice.BoxedArguments(readOnly = false) Object[] value) {
private static void enter(@Advice.AllArguments(readOnly = false, typing = Assigner.Typing.DYNAMIC) Object[] value) {
value = new Object[]{(byte) NUMERIC_VALUE};
}
}
Expand All @@ -111,7 +111,7 @@ public short foo(short value) {
}

@Advice.OnMethodEnter
private static void enter(@Advice.BoxedArguments(readOnly = false) Object[] value) {
private static void enter(@Advice.AllArguments(readOnly = false, typing = Assigner.Typing.DYNAMIC) Object[] value) {
value = new Object[]{(short) NUMERIC_VALUE};
}
}
Expand All @@ -124,7 +124,7 @@ public char foo(char value) {
}

@Advice.OnMethodEnter
private static void enter(@Advice.BoxedArguments(readOnly = false) Object[] value) {
private static void enter(@Advice.AllArguments(readOnly = false, typing = Assigner.Typing.DYNAMIC) Object[] value) {
value = new Object[]{(char) NUMERIC_VALUE};
}
}
Expand All @@ -137,7 +137,7 @@ public int foo(int value) {
}

@Advice.OnMethodEnter
private static void enter(@Advice.BoxedArguments(readOnly = false) Object[] value) {
private static void enter(@Advice.AllArguments(readOnly = false, typing = Assigner.Typing.DYNAMIC) Object[] value) {
value = new Object[]{(int) NUMERIC_VALUE};
}
}
Expand All @@ -150,7 +150,7 @@ public long foo(long value) {
}

@Advice.OnMethodEnter
private static void enter(@Advice.BoxedArguments(readOnly = false) Object[] value) {
private static void enter(@Advice.AllArguments(readOnly = false, typing = Assigner.Typing.DYNAMIC) Object[] value) {
value = new Object[]{(long) NUMERIC_VALUE};
}
}
Expand All @@ -163,7 +163,7 @@ public float foo(float value) {
}

@Advice.OnMethodEnter
private static void enter(@Advice.BoxedArguments(readOnly = false) Object[] value) {
private static void enter(@Advice.AllArguments(readOnly = false, typing = Assigner.Typing.DYNAMIC) Object[] value) {
value = new Object[]{(float) NUMERIC_VALUE};
}
}
Expand All @@ -176,7 +176,7 @@ public double foo(double value) {
}

@Advice.OnMethodEnter
private static void enter(@Advice.BoxedArguments(readOnly = false) Object[] value) {
private static void enter(@Advice.AllArguments(readOnly = false, typing = Assigner.Typing.DYNAMIC) Object[] value) {
value = new Object[]{(double) NUMERIC_VALUE};
}
}
Expand All @@ -189,7 +189,7 @@ public String foo(String value) {
}

@Advice.OnMethodEnter
private static void enter(@Advice.BoxedArguments(readOnly = false) Object[] value) {
private static void enter(@Advice.AllArguments(readOnly = false, typing = Assigner.Typing.DYNAMIC) Object[] value) {
value = new Object[]{FOO};
}
}
Expand All @@ -202,7 +202,7 @@ public Object foo(Object value) {
}

@Advice.OnMethodEnter
private static void enter(@Advice.BoxedArguments(readOnly = false) Object[] value) {
private static void enter(@Advice.AllArguments(readOnly = false, typing = Assigner.Typing.DYNAMIC) Object[] value) {
value = new Object[]{FOO};
}
}
Expand Down
Expand Up @@ -2,6 +2,7 @@

import net.bytebuddy.ByteBuddy;
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
import net.bytebuddy.implementation.bytecode.assign.Assigner;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
Expand Down Expand Up @@ -64,7 +65,7 @@ public void foo() {
}

@Advice.OnMethodExit
private static void exit(@Advice.BoxedReturn(readOnly = false) Object value) {
private static void exit(@Advice.Return(readOnly = false, typing = Assigner.Typing.DYNAMIC) Object value) {
value = FOO;
}
}
Expand All @@ -77,7 +78,7 @@ public boolean foo() {
}

@Advice.OnMethodExit
private static void exit(@Advice.BoxedReturn(readOnly = false) Object value) {
private static void exit(@Advice.Return(readOnly = false, typing = Assigner.Typing.DYNAMIC) Object value) {
value = true;
}
}
Expand All @@ -90,7 +91,7 @@ public byte foo() {
}

@Advice.OnMethodExit
private static void exit(@Advice.BoxedReturn(readOnly = false) Object value) {
private static void exit(@Advice.Return(readOnly = false, typing = Assigner.Typing.DYNAMIC) Object value) {
value = NUMERIC_VALUE;
}
}
Expand All @@ -103,7 +104,7 @@ public short foo() {
}

@Advice.OnMethodExit
private static void exit(@Advice.BoxedReturn(readOnly = false) Object value) {
private static void exit(@Advice.Return(readOnly = false, typing = Assigner.Typing.DYNAMIC) Object value) {
value = (short) NUMERIC_VALUE;
}
}
Expand All @@ -116,7 +117,7 @@ public char foo() {
}

@Advice.OnMethodExit
private static void exit(@Advice.BoxedReturn(readOnly = false) Object value) {
private static void exit(@Advice.Return(readOnly = false, typing = Assigner.Typing.DYNAMIC) Object value) {
value = (char) NUMERIC_VALUE;
}
}
Expand All @@ -129,7 +130,7 @@ public int foo() {
}

@Advice.OnMethodExit
private static void exit(@Advice.BoxedReturn(readOnly = false) Object value) {
private static void exit(@Advice.Return(readOnly = false, typing = Assigner.Typing.DYNAMIC) Object value) {
value = (int) NUMERIC_VALUE;
}
}
Expand All @@ -142,7 +143,7 @@ public long foo() {
}

@Advice.OnMethodExit
private static void exit(@Advice.BoxedReturn(readOnly = false) Object value) {
private static void exit(@Advice.Return(readOnly = false, typing = Assigner.Typing.DYNAMIC) Object value) {
value = (long) NUMERIC_VALUE;
}
}
Expand All @@ -155,7 +156,7 @@ public float foo() {
}

@Advice.OnMethodExit
private static void exit(@Advice.BoxedReturn(readOnly = false) Object value) {
private static void exit(@Advice.Return(readOnly = false, typing = Assigner.Typing.DYNAMIC) Object value) {
value = (float) NUMERIC_VALUE;
}
}
Expand All @@ -168,7 +169,7 @@ public double foo() {
}

@Advice.OnMethodExit
private static void exit(@Advice.BoxedReturn(readOnly = false) Object value) {
private static void exit(@Advice.Return(readOnly = false, typing = Assigner.Typing.DYNAMIC) Object value) {
value = (double) NUMERIC_VALUE;
}
}
Expand All @@ -181,7 +182,7 @@ public String foo() {
}

@Advice.OnMethodExit
private static void exit(@Advice.BoxedReturn(readOnly = false) Object value) {
private static void exit(@Advice.Return(readOnly = false, typing = Assigner.Typing.DYNAMIC) Object value) {
value = FOO;
}
}
Expand Down
Expand Up @@ -11,6 +11,7 @@
import net.bytebuddy.implementation.Implementation;
import net.bytebuddy.implementation.bytecode.ByteCodeAppender;
import net.bytebuddy.implementation.bytecode.StackSize;
import net.bytebuddy.implementation.bytecode.assign.Assigner;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
Expand Down Expand Up @@ -111,7 +112,7 @@ public void testInconsistentStackSizeAdvice() throws Exception {
private static class ExitAdvice {

@Advice.OnMethodExit
private static void exit(@Advice.BoxedReturn(readOnly = false) Object returned, @Value Object value) {
private static void exit(@Advice.Return(readOnly = false, typing = Assigner.Typing.DYNAMIC) Object returned, @Value Object value) {
returned = value;
}
}
Expand Down

0 comments on commit c4bf7db

Please sign in to comment.