Skip to content

Commit d6e76cb

Browse files
committed
Add sync to loadClass.
1 parent f2149a6 commit d6e76cb

1 file changed

Lines changed: 27 additions & 25 deletions

File tree

framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,44 +1967,46 @@ public BundleImpl getBundle()
19671967
protected Class loadClass(String name, boolean resolve)
19681968
throws ClassNotFoundException
19691969
{
1970+
synchronized (getClassLoadingLock(name)) {
19701971
Class clazz = findLoadedClass(name);
19711972

19721973
if (clazz == null)
19731974
{
1974-
try
1975-
{
1976-
clazz = (Class) m_wiring.findClassOrResourceByDelegation(name, true);
1977-
}
1978-
catch (ResourceNotFoundException ex)
1979-
{
1980-
// This should never happen since we are asking for a class,
1981-
// so just ignore it.
1982-
}
1983-
catch (ClassNotFoundException cnfe)
1984-
{
1985-
ClassNotFoundException ex = cnfe;
1986-
if (m_logger.getLogLevel() >= Logger.LOG_DEBUG)
1987-
{
1988-
String msg = diagnoseClassLoadError(m_wiring.m_resolver, m_wiring.m_revision, name);
1989-
ex = (msg != null)
1990-
? new ClassNotFoundException(msg, cnfe)
1991-
: ex;
1992-
}
1993-
throw ex;
1994-
}
1995-
if (clazz == null)
1975+
try
1976+
{
1977+
clazz = (Class) m_wiring.findClassOrResourceByDelegation(name, true);
1978+
}
1979+
catch (ResourceNotFoundException ex)
1980+
{
1981+
// This should never happen since we are asking for a class,
1982+
// so just ignore it.
1983+
}
1984+
catch (ClassNotFoundException cnfe)
1985+
{
1986+
ClassNotFoundException ex = cnfe;
1987+
if (m_logger.getLogLevel() >= Logger.LOG_DEBUG)
19961988
{
1997-
// We detected a cycle
1998-
throw new ClassNotFoundException("Cycle detected while trying to load class: " + name);
1989+
String msg = diagnoseClassLoadError(m_wiring.m_resolver, m_wiring.m_revision, name);
1990+
ex = (msg != null)
1991+
? new ClassNotFoundException(msg, cnfe)
1992+
: ex;
19991993
}
1994+
throw ex;
1995+
}
1996+
if (clazz == null)
1997+
{
1998+
// We detected a cycle
1999+
throw new ClassNotFoundException("Cycle detected while trying to load class: " + name);
2000+
}
20002001
}
20012002

20022003
// Resolve the class and return it.
20032004
if (resolve)
20042005
{
2005-
resolveClass(clazz);
2006+
resolveClass(clazz);
20062007
}
20072008
return clazz;
2009+
}
20082010
}
20092011

20102012
@Override

0 commit comments

Comments
 (0)