NoClassDefFoundError on JFace FontRegistry

When I launch the SWT application (via the Eclipse startup profile), I get the following stack trace:

Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/jface/resource/FontRegistry
    at org.eclipse.jface.resource.JFaceResources.getFontRegistry(JFaceResources.java:338)
    at org.eclipse.jface.window.Window.close(Window.java:313)
    at org.eclipse.jface.dialogs.Dialog.close(Dialog.java:971)
    at org.eclipse.jface.dialogs.ProgressMonitorDialog.close(ProgressMonitorDialog.java:348)
    at org.eclipse.jface.dialogs.ProgressMonitorDialog.finishedRun(ProgressMonitorDialog.java:582)
    at org.eclipse.jface.dialogs.ProgressMonitorDialog.run(ProgressMonitorDialog.java:498)
    at com.blah.si.workflow.SWTApplication.main(SWTApplication.java:135)

Now, what does this odd do:

  • When I change the build path of the project and replace jface.jar with the original project (the same version is 3.3.1), the error disappears.
  • In other applications that use the same ATM, and a copy of the same startup profile and project, everything works fine.
  • This is NOT a ClassNotFoundException. A class is on its way to classes. If I attach the source to the jar, I can debug the getFontRegistry method. The method will execute successfully several times before finally throwing a lineNoClassDefFoundErroron line 338. Line 337 is the if variable == null statement that checks whether a static variable has been initialized. Line 338 initializes it, if it is not yet initialized. For the first time, with the completion of the zero check, initialization is performed. Subsequent passes through the method pass a zero check, and thus, an already initialized static value is returned. On the last pass (the one that fails), the null check completes again (even if the static variable is already initialized), and when it tries to reinitialize the static variable, it is generated NoClassDefFoundError. Here is the corresponding source (starting at line 336, note that fontRegistry is a private static variable that is not set anywhere else):

.

public static FontRegistry getFontRegistry() {
   if (fontRegistry == null) {
     fontRegistry = new FontRegistry(
         "org.eclipse.jface.resource.jfacefonts");
   }
   return fontRegistry;
}

.

  • ( , ) .classpath .project . .

- № 3 , - wierd classloader - , ?

?

:. , Pourquoi Litytestdata, , try 458 ProgressMonitorDialog. , , finally. ( JFontRegistry , , - .) , , , Pourquoi, . .

+3
5

, stacktrace . run org.eclipse.jface.dialogs.ProgressMonitorDialog ( , ):

public void run(boolean fork, boolean cancelable,
         IRunnableWithProgress runnable) throws InvocationTargetException,
         InterruptedException {
     setCancelable(cancelable);
     try {
         aboutToRun();
         // Let the progress monitor know if they need to update in UI Thread
         progressMonitor.forked = fork;
         ModalContext.run(runnable, fork, getProgressMonitor(), getShell()
                 .getDisplay());
     } finally {
         finishedRun();  // this is line 498
     }
}

Jared stacktrace - 498 , finishedRun() finally. , - , try. finally , .

+2

, JAR, , 2006 , Sanjiv JIVAN:

ClassNotFoundException NoClassDefFoundError

A ClassNotFoundException , ClassLoader.
, CLASSPATH.
, , , , ClassLoader, , , ClassLoader .
, (WebSphere ClassLoader).

java.lang.NoClassDefFoundError java.lang.ClassNotFoundException. .

, ( , java.lang.NoClassDefFoundError java.lang.Error),

java.lang.NoClassDefFoundError:
org/apache/activemq/ActiveMQConnectionFactory

, ActiveMQConnectionFactory CLASSPATH.

, .

, ActiveMQConnectionFactory ClassLoader, , .

, , , ClassLoader.

, , (ActiveMQConnectionFactory ) , .
, , JAD.

, , , , , SomeClass CLASSPATH.

private static SomeClass foo = new SomeClass();

. , , - jarFinder. , .
jarhoo , .

, jar , jarscan. , , , , zip .

+3

, , , , :

try
{
    final Class       clazz;
    final ClassLoader loader;

    clazz  = Class.forName("org/eclipse/jface/resource/FontRegistry");
    loader = clazz.getClassLoader(); 
    System.out.println("The classloader at step 1 is: " + loader);
}
catch(final Throwable ex)
{
    ex.printStackTrace();
}

, NoClassDefFoundError , .

, ClassLoader . , ? .

+2

TofuBeer, NoClassDefFoundError , :

  • class org.eclipse.jface.resource.FontRegistry ClassLoader,
  • , , , Class, ClassLoader.

org.eclipse.jface.resource.FontRegistry :

( ).

org.eclipse.jface.resource.JFaceResources

getFontRegistry(), , staticRegistry:

/**
 * The JFace font registry; <code>null</code> until lazily initialized or
 * explicitly set.
 */
private static FontRegistry fontRegistry = null;

, begs question: null ?

- FontRegistry JFaceResources gc?!

, , , (, ) . , , (§12.4).

, , , , .


eclipse,

:
, XYZ.
, JAR XYZ Java, .classpath.
, : java.lang.NoClassDefFoundError: XYZ.SomeClass.

" " .
, runtime Eclipse.

.
plugin.xml , XYZ .
plugin.xml.
.

.classpath, .
, . , .

+1

FontRegistry ( TofoBeer), , JAR , FontRegistry.

org.eclipse.core.commands_xxxxx.jar

JAR .

+1
source

Source: https://habr.com/ru/post/1703984/


All Articles