You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2009/04/22 23:38:00 UTC
svn commit: r767676 -
/felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleImpl.java
Author: rickhall
Date: Wed Apr 22 21:38:00 2009
New Revision: 767676
URL: http://svn.apache.org/viewvc?rev=767676&view=rev
Log:
Commit workaround for a JDK bug that results in a ClassCircularityError.
(FELIX-1045)
Modified:
felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleImpl.java
Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleImpl.java?rev=767676&r1=767675&r2=767676&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleImpl.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/searchpolicy/ModuleImpl.java Wed Apr 22 21:38:00 2009
@@ -1263,58 +1263,30 @@
&& !Proxy.class.equals(clazz);
}
- private volatile static Method getEnclosingClassMethod = null;
- private volatile static boolean getEnclosingClassMethodInitialized = false;
-
private static Class getEnclosingClass(Class clazz)
{
- if (!getEnclosingClassMethodInitialized)
+ // This code determines if the class is an inner class and if so
+ // returns the enclosing class. At one point in time this code used
+ // Class.getEnclosingClass() for JDKs > 1.5, but due to a bug in the
+ // JDK which caused invalid ClassCircularityErrors we had to remove it.
+ int idx = clazz.getName().lastIndexOf('$');
+ if (idx > 0)
{
- // Check if we have the getEnclosingClass() method available from
- // JDK 1.5.
+ ClassLoader cl = (clazz.getClassLoader() != null)
+ ? clazz.getClassLoader() : ClassLoader.getSystemClassLoader();
try
{
- getEnclosingClassMethod =
- Class.class.getDeclaredMethod("getEnclosingClass", null);
- }
- catch (NoSuchMethodException ex)
- {
- // Ignore it then.
- }
- getEnclosingClassMethodInitialized = true;
- }
- if (getEnclosingClassMethod != null)
- {
- try
- {
- Class enclosing = (Class) getEnclosingClassMethod.invoke(clazz, null);
+ Class enclosing = cl.loadClass(clazz.getName().substring(0, idx));
clazz = (enclosing != null) ? enclosing : clazz;
}
catch (Throwable t)
{
- // Ignore everything and use original class.
- }
- }
- else
- {
- // If we are not on JDK 1.5, try to figure out enclosing class.
- int idx = clazz.getName().lastIndexOf('$');
- if (idx > 0)
- {
- ClassLoader cl = clazz.getClassLoader() != null ? clazz.getClassLoader() : ClassLoader.getSystemClassLoader();
- try
- {
- Class enclosing = cl.loadClass(clazz.getName().substring(0, idx));
- clazz = (enclosing != null) ? enclosing : clazz;
- }
- catch (Throwable t)
- {
- // Ignore all problems since we are trying to load a class
- // inside the class loader and this can lead to
- // ClassCircularityError, for example.
- }
+ // Ignore all problems since we are trying to load a class
+ // inside the class loader and this can lead to
+ // ClassCircularityError, for example.
}
}
+
return clazz;
}