[jboss-cvs] JBossAS SVN: r105603 - in projects/jboss-reflect/trunk/src: test/java/org/jboss/test/classinfo/test and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jun 2 18:41:20 EDT 2010
Author: kabir.khan at jboss.com
Date: 2010-06-02 18:41:19 -0400 (Wed, 02 Jun 2010)
New Revision: 105603
Added:
projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/ClassInfoWithMethodReturningObjectArray.java
Modified:
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/BytecodeTypeInfoFactoryImpl.java
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/ClassLoaderFinder.java
projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/BytecodeArrayUnitTestCase.java
projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/ClassInfoArrayTest.java
Log:
[JBREFLECT-125] Make sure we clean up array names before trying to get the classloader
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/BytecodeTypeInfoFactoryImpl.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/BytecodeTypeInfoFactoryImpl.java 2010-06-02 21:29:07 UTC (rev 105602)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/BytecodeTypeInfoFactoryImpl.java 2010-06-02 22:41:19 UTC (rev 105603)
@@ -111,6 +111,16 @@
private ClassLoader findClassLoaderForClass(ClassLoader initiating, String name)
{
+ int start = 0;
+ while (name.charAt(start) == '[')
+ start++;
+
+ int end = name.length() - 1;
+ while (end > start && name.charAt(end) == ']' && name.charAt(end - 1) == '[')
+ end -= 2;
+
+ if (start > 0 || end < name.length() - 1)
+ name = name.substring(0, end + 1);
return finder.getLoaderForClass(initiating, name);
}
@@ -354,7 +364,9 @@
//TODO If the class was an array we need some way to find the classloader for that
real = findClassLoaderForClass(cl, name);
- if (real != null && real != cl)
+ if (real == null)
+ real = cl;
+ else if (real != cl)
{
//Make sure that we check the cache of the classloader actually containing the class
classLoaderCache = getClassLoaderCache(real);
@@ -362,6 +374,7 @@
if (result != null)
return result;
}
+
classBytes = loadClassBytes(real, name);
}
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/ClassLoaderFinder.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/ClassLoaderFinder.java 2010-06-02 21:29:07 UTC (rev 105602)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/ClassLoaderFinder.java 2010-06-02 22:41:19 UTC (rev 105603)
@@ -34,7 +34,7 @@
*
* @param initiating the initiating classloader
* @param name the name of the class
- * @return the classloader to use to load the class
+ * @return the classloader to use to load the class, or null if the class does not exist
*/
ClassLoader getLoaderForClass(ClassLoader initiating, String name);
@@ -50,6 +50,7 @@
private Default()
{
}
+
public ClassLoader getLoaderForClass(ClassLoader initiating, String name)
{
return initiating;
Modified: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/BytecodeArrayUnitTestCase.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/BytecodeArrayUnitTestCase.java 2010-06-02 21:29:07 UTC (rev 105602)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/BytecodeArrayUnitTestCase.java 2010-06-02 22:41:19 UTC (rev 105603)
@@ -24,6 +24,7 @@
import junit.framework.Test;
import org.jboss.reflect.plugins.bytecode.BytecodeTypeInfoFactory;
+import org.jboss.reflect.plugins.bytecode.ClassLoaderFinder;
import org.jboss.reflect.spi.PackageInfo;
import org.jboss.reflect.spi.TypeInfoFactory;
@@ -45,6 +46,37 @@
return suite(BytecodeArrayUnitTestCase.class);
}
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ ((BytecodeTypeInfoFactory)getTypeInfoFactory()).setClassLoaderFinder(new ClassLoaderFinder()
+ {
+
+ public ClassLoader getLoaderForClass(ClassLoader initiating, String name)
+ {
+ if (name.contains("[") || name.contains("]"))
+ fail("Bad name " + name);
+ try
+ {
+ initiating.loadClass(name);
+ }
+ catch (ClassNotFoundException e)
+ {
+ }
+ return initiating;
+ }
+ });
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ ((BytecodeTypeInfoFactory)getTypeInfoFactory()).setClassLoaderFinder(null);
+ super.tearDown();
+ }
+
protected void assertNullPackageInfo(PackageInfo packageInfo)
{
// TODO JBREFLECT-113 this is broken for javassist
Modified: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/ClassInfoArrayTest.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/ClassInfoArrayTest.java 2010-06-02 21:29:07 UTC (rev 105602)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/ClassInfoArrayTest.java 2010-06-02 22:41:19 UTC (rev 105603)
@@ -23,6 +23,8 @@
import org.jboss.reflect.plugins.ArrayInfoImpl;
import org.jboss.reflect.spi.ArrayInfo;
+import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.reflect.spi.MethodInfo;
import org.jboss.reflect.spi.TypeInfo;
import org.jboss.reflect.spi.TypeInfoFactory;
import org.jboss.test.classinfo.support.ClassInfoAnnotationClass;
@@ -129,6 +131,15 @@
testArray(array);
}
+ public void testReturnedArray() throws Throwable
+ {
+ ClassInfo info = assertInstanceOf(getTypeInfoFactory().getTypeInfo(ClassInfoWithMethodReturningObjectArray.class), ClassInfo.class);
+ MethodInfo minfo = info.getDeclaredMethod("method");
+ assertNotNull(minfo);
+ TypeInfo array = minfo.getReturnType();
+ assertNotNull(array);
+ }
+
private void testArray(Object array) throws Throwable
{
TypeInfoFactory factory = getTypeInfoFactory();
Added: projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/ClassInfoWithMethodReturningObjectArray.java
===================================================================
--- projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/ClassInfoWithMethodReturningObjectArray.java (rev 0)
+++ projects/jboss-reflect/trunk/src/test/java/org/jboss/test/classinfo/test/ClassInfoWithMethodReturningObjectArray.java 2010-06-02 22:41:19 UTC (rev 105603)
@@ -0,0 +1,35 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.classinfo.test;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassInfoWithMethodReturningObjectArray
+{
+ public Object[] method()
+ {
+ return null;
+ }
+}
More information about the jboss-cvs-commits
mailing list