From 9cfa81cce09bda5c7fccf4710e8c357977bfdaf2 Mon Sep 17 00:00:00 2001
From: chibash -version 3.25
+Changes
+
+
+
-version 3.24 on November 1, 2018
-version 3.25 +
-version 3.24.1 on December 9, 2018
-version 3.25 +
-version 3.24.1 on December 9, 2018
-version 3.25
-version 3.24.1 on December 9, 2018
--
cgit v1.2.3
From d64a1c8ab01215236790b6601c6ce06dc324a05c Mon Sep 17 00:00:00 2001
From: michalkurka -version 3.25
-version 3.24.1 on December 9, 2018
diff --git a/src/main/javassist/util/proxy/ProxyFactory.java b/src/main/javassist/util/proxy/ProxyFactory.java
index ae368b2a..98e352ca 100644
--- a/src/main/javassist/util/proxy/ProxyFactory.java
+++ b/src/main/javassist/util/proxy/ProxyFactory.java
@@ -472,6 +472,10 @@ public class ProxyFactory {
/**
* Generates a proxy class using the current filter.
+ * It loads a class file by the given
+ * {@code java.lang.invoke.MethodHandles.Lookup} object,
+ * which can be obtained by {@code MethodHandles.lookup()} called from
+ * somewhere in the package that the loaded class belongs to.
*
* @param lookup used for loading the proxy class.
* It needs an appropriate right to invoke {@code defineClass}
@@ -492,6 +496,7 @@ public class ProxyFactory {
* It needs an appropriate right to invoke {@code defineClass}
* for the proxy class.
* @param filter the filter.
+ * @see #createClass(Lookup)
* @since 3.24
*/
public Class> createClass(Lookup lookup, MethodFilter filter) {
diff --git a/src/test/test5/SwitchCase.java b/src/test/test5/SwitchCase.java
new file mode 100644
index 00000000..7a0ebe21
--- /dev/null
+++ b/src/test/test5/SwitchCase.java
@@ -0,0 +1,5 @@
+package test5;
+
+public class SwitchCase {
+ public static final String STR1 = "foo";
+}
--
cgit v1.2.3
From 6ea8021f1517ee2923bd5d50dc466594ac7f68bf Mon Sep 17 00:00:00 2001
From: chibash -version 3.25
-version 3.24.1 on December 9, 2018
diff --git a/javassist.jar b/javassist.jar
index 89913dc5..c198d0e3 100644
Binary files a/javassist.jar and b/javassist.jar differ
diff --git a/src/main/javassist/CtBehavior.java b/src/main/javassist/CtBehavior.java
index 1b9dbf0b..a0738ec7 100644
--- a/src/main/javassist/CtBehavior.java
+++ b/src/main/javassist/CtBehavior.java
@@ -782,7 +782,7 @@ public abstract class CtBehavior extends CtMember {
Modifier.isStatic(getModifiers()));
jv.recordParamNames(ca, nvars);
jv.recordLocalVariables(ca, 0);
- jv.recordType(getReturnType0());
+ jv.recordReturnType(getReturnType0(), false);
jv.compileStmnt(src);
Bytecode b = jv.getBytecode();
int stack = b.getMaxStack();
diff --git a/src/test/javassist/JvstTest5.java b/src/test/javassist/JvstTest5.java
index 1a9bd666..915e1e1a 100644
--- a/src/test/javassist/JvstTest5.java
+++ b/src/test/javassist/JvstTest5.java
@@ -484,4 +484,18 @@ public class JvstTest5 extends JvstTestRoot {
Object obj = make(cc.getName());
assertEquals(1, invoke(obj, "run"));
}
+
+ // Issue #241
+ public void testInsertBeforeAndDollarR() throws Exception {
+ CtClass cc = sloader.get(test5.InsertBeforeDollarR.class.getName());
+ CtMethod m = cc.getDeclaredMethod("foo");
+ m.insertBefore("{ if ($1 == 1) return ($r)$2; }");
+ try {
+ m.insertBefore("{ $_ = \"bar\"; }");
+ assertTrue(false);
+ } catch (CannotCompileException e) {}
+ cc.writeFile();
+ Object obj = make(cc.getName());
+ assertEquals(1, invoke(obj, "run"));
+ }
}
diff --git a/src/test/test5/InsertBeforeDollarR.java b/src/test/test5/InsertBeforeDollarR.java
new file mode 100644
index 00000000..a2c32aae
--- /dev/null
+++ b/src/test/test5/InsertBeforeDollarR.java
@@ -0,0 +1,14 @@
+package test5;
+
+public class InsertBeforeDollarR {
+ public int run() {
+ if (foo(1, "baz").equals("baz"))
+ return 1;
+ else
+ return 0;
+ }
+
+ public String foo(int i, Object obj) {
+ return String.valueOf(i);
+ }
+}
--
cgit v1.2.3
From c85bc4f090044d657419f82b5fc33434ab911c62 Mon Sep 17 00:00:00 2001
From: shifujun Then the static method must be something like this:
+ *
+ * The into the bytecode equivalent to:
+ *
+ * -version 3.25
-version 3.24.1 on December 9, 2018
diff --git a/javassist.jar b/javassist.jar
index c198d0e3..f9e84222 100644
Binary files a/javassist.jar and b/javassist.jar differ
--
cgit v1.2.3
-
-
move()
:
+ *
+ * class Point {
+ * Point move(int x, int y) { ... }
+ * }
+ *
+ * class Verbose {
+ * static Point print(Point target, int x, int y) { ... }
+ * }
+ *
+ * CodeConverter
would translate bytecode
+ * equivalent to:
+ *
+ * Point p2 = p.move(x + y, 0);
+ *
+ * Point p2 = Verbose.print(p, x + y, 0);
+ *
+ * @param origMethod original method
+ * @param staticMethod static method
+ */
+ public void redirectMethodCallToStatic(CtMethod origMethod,
+ CtMethod staticMethod) {
+ transformers = new TransformCallToStatic(transformers, origMethod,
+ staticMethod);
+ }
+
/**
* Insert a call to another method before an existing method call.
* That "before" method must be static. The return type must be
diff --git a/src/main/javassist/convert/TransformCallToStatic.java b/src/main/javassist/convert/TransformCallToStatic.java
new file mode 100644
index 00000000..87181edf
--- /dev/null
+++ b/src/main/javassist/convert/TransformCallToStatic.java
@@ -0,0 +1,29 @@
+package javassist.convert;
+
+import javassist.CtMethod;
+import javassist.bytecode.BadBytecode;
+import javassist.bytecode.CodeIterator;
+import javassist.bytecode.ConstPool;
+import javassist.bytecode.Descriptor;
+import javassist.bytecode.Opcode;
+
+public class TransformCallToStatic extends TransformCall {
+ public TransformCallToStatic(Transformer next, CtMethod origMethod, CtMethod substMethod) {
+ super(next, origMethod, substMethod);
+ methodDescriptor = origMethod.getMethodInfo2().getDescriptor();
+ }
+
+ @Override
+ protected int match(int c, int pos, CodeIterator iterator, int typedesc, ConstPool cp) {
+ if (newIndex == 0) {
+ String desc = Descriptor.insertParameter(classname, methodDescriptor);
+ int nt = cp.addNameAndTypeInfo(newMethodname, desc);
+ int ci = cp.addClassInfo(newClassname);
+ newIndex = cp.addMethodrefInfo(ci, nt);
+ constPool = cp;
+ }
+ iterator.writeByte(Opcode.INVOKESTATIC, pos);
+ iterator.write16bit(newIndex, pos + 1);
+ return pos;
+ }
+}
diff --git a/src/test/javassist/JvstTest3.java b/src/test/javassist/JvstTest3.java
index 46f06b16..c065170c 100644
--- a/src/test/javassist/JvstTest3.java
+++ b/src/test/javassist/JvstTest3.java
@@ -586,6 +586,20 @@ public class JvstTest3 extends JvstTestRoot {
assertEquals(524, invoke(obj, "test"));
}
+ public void testMethodRedirectToStatic() throws Exception {
+ CtClass targetClass = sloader.get("test3.MethodRedirectToStatic");
+ CtClass staticClass = sloader.get("test3.MethodRedirectToStatic2");
+ CtMethod targetMethod = targetClass.getDeclaredMethod("add");
+ CtMethod staticMethod = staticClass.getDeclaredMethod("add2");
+ CodeConverter conv = new CodeConverter();
+
+ conv.redirectMethodCallToStatic(targetMethod, staticMethod);
+ targetClass.instrument(conv);
+ targetClass.writeFile();
+ Object obj = make(targetClass.getName());
+ assertEquals(30, invoke(obj, "test"));
+ }
+
public void testClassMap() throws Exception {
ClassMap map = new ClassMap();
map.put("aa", "AA");
diff --git a/src/test/test3/MethodRedirectToStatic.java b/src/test/test3/MethodRedirectToStatic.java
new file mode 100644
index 00000000..f1d68e35
--- /dev/null
+++ b/src/test/test3/MethodRedirectToStatic.java
@@ -0,0 +1,22 @@
+package test3;
+
+public class MethodRedirectToStatic {
+
+ public static void main(String[] args) {
+ System.out.println(new MethodRedirectToStatic().test());
+ }
+
+ int add(int a, int b) {
+ return a + b;
+ }
+
+ public int test() {
+ return add(1, 2);
+ }
+}
+
+class MethodRedirectToStatic2 {
+ public static int add2(MethodRedirectToStatic target, int a, int b) {
+ return target.add(a * 10, b * 10);
+ }
+}
--
cgit v1.2.3
From f36195c1451c79b9d46618716cf4efe9904afb32 Mon Sep 17 00:00:00 2001
From: chibash
-