]> source.dussan.org Git - javassist.git/commitdiff
fixed regression introduced by fix to ProxyFactory -- fixes JASSIST-113
authoradinn <adinn@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>
Tue, 13 Apr 2010 09:00:47 +0000 (09:00 +0000)
committeradinn <adinn@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>
Tue, 13 Apr 2010 09:00:47 +0000 (09:00 +0000)
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@527 30ef5769-5b8d-40dd-aea6-55b5d6557bb3

src/main/javassist/util/proxy/ProxyFactory.java
src/test/test/javassist/proxy/JASSIST113RegressionTest.java [new file with mode: 0644]

index 21e39d4cddb087f2378de3af182a085ee106a04b..07509509d1f3d02811f784638970ff16705dc1a5 100644 (file)
@@ -157,8 +157,8 @@ public class ProxyFactory {
     private List signatureMethods;
     private byte[] signature;
     private String classname;
+    private String basename;
     private String superName;
-    private String packageName;
     private Class thisClass;
     /**
      * per factory setting initialised from current setting for useCache but able to be reset before each create call
@@ -736,21 +736,24 @@ public class ProxyFactory {
 
         if (superClass == null) {
             superClass = OBJECT_TYPE;
+            superName = superClass.getName();
+            basename = interfaces.length == 0 ? superName
+                                               : interfaces[0].getName();
+        } else {
+            superName = superClass.getName();
+            basename = superName;
         }
-        superName = superClass.getName();
 
         if (Modifier.isFinal(superClass.getModifiers()))
             throw new RuntimeException(superName + " is final");
-        packageName = getPackageName(superName);
-        if (packageName.startsWith("java."))
-            packageName = "org.javassist.tmp." + packageName;
+        
+        if (basename.startsWith("java."))
+            basename = "org.javassist.tmp." + basename;
     }
 
     private void allocateClassName()
     {
-        classname = makeProxyName(superName);
-        if (classname.startsWith("java."))
-            classname = "org.javassist.tmp." + classname;
+        classname = makeProxyName(basename);
     }
 
     private static Comparator sorter = new Comparator() {
@@ -786,7 +789,7 @@ public class ProxyFactory {
             Method m = (Method)e.getValue();
             int mod = m.getModifiers();
             if (!Modifier.isFinal(mod) && !Modifier.isStatic(mod)
-                    && isVisible(mod, packageName, m) && (filter == null || filter.isHandled(m))) {
+                    && isVisible(mod, basename, m) && (filter == null || filter.isHandled(m))) {
                 setBit(signature, idx);
             }
         }
@@ -948,7 +951,7 @@ public class ProxyFactory {
             Constructor c = cons[i];
             int mod = c.getModifiers();
             if (!Modifier.isFinal(mod) && !Modifier.isPrivate(mod)
-                    && isVisible(mod, packageName, c)) {
+                    && isVisible(mod, basename, c)) {
                 MethodInfo m = makeConstructor(thisClassName, c, cp, superClass, doHandlerInit);
                 cf.addMethod(m);
             }
@@ -984,17 +987,18 @@ public class ProxyFactory {
      *
      * @param mod       the modifiers of the method. 
      */
-    private static boolean isVisible(int mod, String fromPackage, Member meth) {
+    private static boolean isVisible(int mod, String from, Member meth) {
         if ((mod & Modifier.PRIVATE) != 0)
             return false;
         else if ((mod & (Modifier.PUBLIC | Modifier.PROTECTED)) != 0)
             return true;
         else {
+            String p = getPackageName(from);
             String q = getPackageName(meth.getDeclaringClass().getName());
-            if (fromPackage == null)
+            if (p == null)
                 return q == null;
             else
-                return fromPackage.equals(q);
+                return p.equals(q);
         }
     }
 
diff --git a/src/test/test/javassist/proxy/JASSIST113RegressionTest.java b/src/test/test/javassist/proxy/JASSIST113RegressionTest.java
new file mode 100644 (file)
index 0000000..baecdb9
--- /dev/null
@@ -0,0 +1,22 @@
+package test.javassist.proxy;
+
+import javassist.util.proxy.ProxyFactory;
+import junit.framework.TestCase;
+
+/**
+ * Test for regression error detailed in JASSIST-113
+ */
+public class JASSIST113RegressionTest extends TestCase
+{
+    interface Bear
+    {
+        void hibernate();
+    }
+
+    public void testProxyFactoryWithNonPublicInterface()
+    {
+        ProxyFactory proxyFactory = new ProxyFactory();
+        proxyFactory.setInterfaces(new Class[]{Bear.class});
+        proxyFactory.createClass();
+    }
+}