Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.NoClassDefFoundError: in anonymous inner class

Im' running this code on a Linux Red Hat with the sun/oracle JVM 1.6_23, inside a VMWare server.

After some times the JVM seem to be unable to access my anonymous inner classes.

My classpath is fine, since it works for a period.

All i got is errors like this one :

java.lang.NoClassDefFoundError: com/mycompany/impl/MyClassImpl$1 at com.mycompany.impl.MyClassImpl.markAsDeletable(MyClassImpl.java:45).

line 45 is the first line below, it can't find my new Predicate

        DomaineVO domaineVO = Iterables.find(domainesVO, new Predicate<DomaineVO>() {

            @Override
            public boolean apply(DomaineVO input) {
                return input.getId().equals(domaine.getIdentifier().toString());
            }
        });

Any ideas ?

like image 901
oneeyejack Avatar asked May 12 '11 10:05

oneeyejack


People also ask

How do I overcome Java Lang NoClassDefFoundError?

You can fix NoClassDefFoundError error by checking following: Check the exception stack trace to know exactly which class throw the error and which is the class not found by java.

How do you define anonymous inner class?

It is an inner class without a name and for which only a single object is created. An anonymous inner class can be useful when making an instance of an object with certain “extras” such as overriding methods of a class or interface, without having to actually subclass a class.

Can an anonymous inner class contain static methods?

Anonymous classes also have the same restrictions as local classes with respect to their members: You cannot declare static initializers or member interfaces in an anonymous class. An anonymous class can have static members provided that they are constant variables.

Can inner class instantiate anonymously?

Anonymous classes are inner classes with no name. Since they have no name, we can't use them in order to create instances of anonymous classes. As a result, we have to declare and instantiate anonymous classes in a single expression at the point of use. We may either extend an existing class or implement an interface.


2 Answers

Finally, i think we might have put the finger on the problem.

We are running this code on jetty, and we use automatic deploy of the .war files. By default jetty use the java.io.tmpdir to deploy the .war files.

Our problem was only on linux, and mostly early in the morning (as soon as the first office worker use the app).

The cause was the cleaning of the /tmp at night (made by a LOGROTATE command on our servers).

Rules of thumb : Never use /tmp for too long time, and make jetty deploy war in a directory of your own.

Thanks everyone

like image 185
oneeyejack Avatar answered Oct 05 '22 22:10

oneeyejack


It sounds like the JVM can't find the class file for the anonymous class. This would be named 'MyClassImpl$1.class' - if it's not present in the classpath, something must have deleted it. If it is present then there's something wrong with the JVM.

like image 37
Michael Borgwardt Avatar answered Oct 05 '22 22:10

Michael Borgwardt