You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2019/05/15 05:16:11 UTC

[tomee] 02/04: Ensure the method order in bytecode is stable

This is an automated email from the ASF dual-hosted git repository.

dblevins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomee.git

commit d0656d38fee740bfa0a2a2018747a7752986cb42
Author: David Blevins <da...@gmail.com>
AuthorDate: Wed May 15 11:50:13 2019 +0900

    Ensure the method order in bytecode is stable
---
 .../tomee/microprofile/jwt/bval/ValidationGenerator.java     | 12 ++++++++----
 .../microprofile/jwt/bval/data/Colors$$JwtConstraints.java   |  9 +++++----
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/mp-jwt/src/main/java/org/apache/tomee/microprofile/jwt/bval/ValidationGenerator.java b/mp-jwt/src/main/java/org/apache/tomee/microprofile/jwt/bval/ValidationGenerator.java
index d3d2dc3..42a23d9 100644
--- a/mp-jwt/src/main/java/org/apache/tomee/microprofile/jwt/bval/ValidationGenerator.java
+++ b/mp-jwt/src/main/java/org/apache/tomee/microprofile/jwt/bval/ValidationGenerator.java
@@ -28,7 +28,7 @@ import javax.validation.Constraint;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -97,7 +97,7 @@ public class ValidationGenerator implements Opcodes {
 
         if (constrainedMethods.size() == 0) return null;
 
-        final Map<String, MethodVisitor> visitors = new HashMap<>();
+        final Map<String, MethodVisitor> visitors = new LinkedHashMap<>();
 
         final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
 
@@ -116,7 +116,7 @@ public class ValidationGenerator implements Opcodes {
         }
 
         int id = 0;
-        for (final Method method : constrainedMethods) {
+        for (final Method method : sort(constrainedMethods)) {
             final String name = method.getName() + "$$" + (id++);
 
             // Declare a method of return type JsonWebToken for use with
@@ -141,7 +141,6 @@ public class ValidationGenerator implements Opcodes {
 
         DynamicSubclass.copyMethodAnnotations(target, visitors);
 
-        // This should never be reached, but just in case
         for (final MethodVisitor visitor : visitors.values()) {
             visitor.visitEnd();
         }
@@ -149,6 +148,11 @@ public class ValidationGenerator implements Opcodes {
         return cw.toByteArray();
     }
 
+    private static List<Method> sort(final List<Method> constrainedMethods) {
+        constrainedMethods.sort((a, b) -> a.toString().compareTo(b.toString()));
+        return constrainedMethods;
+    }
+
     public static String getName(final Class<?> target) {
         return target.getName() + "$$JwtConstraints";
     }
diff --git a/mp-jwt/src/test/java/org/apache/tomee/microprofile/jwt/bval/data/Colors$$JwtConstraints.java b/mp-jwt/src/test/java/org/apache/tomee/microprofile/jwt/bval/data/Colors$$JwtConstraints.java
index fde57f1..afc456b 100644
--- a/mp-jwt/src/test/java/org/apache/tomee/microprofile/jwt/bval/data/Colors$$JwtConstraints.java
+++ b/mp-jwt/src/test/java/org/apache/tomee/microprofile/jwt/bval/data/Colors$$JwtConstraints.java
@@ -25,15 +25,16 @@ public class Colors$$JwtConstraints {
     public Colors$$JwtConstraints() {
     }
 
-    @Name("public void org.apache.tomee.microprofile.jwt.bval.data.Colors.red()")
+    @Name("public void org.apache.tomee.microprofile.jwt.bval.data.Colors.blue()")
     @Issuer("http://foo.bar.com")
-    public JsonWebToken red$$0() {
+    public JsonWebToken blue$$0() {
         return null;
     }
 
-    @Name("public void org.apache.tomee.microprofile.jwt.bval.data.Colors.blue()")
+    @Name("public void org.apache.tomee.microprofile.jwt.bval.data.Colors.red()")
     @Issuer("http://foo.bar.com")
-    public JsonWebToken blue$$1() {
+    public JsonWebToken red$$1() {
         return null;
     }
+
 }