java.lang.NoClassDefFoundError: in anonymous inner class

房东的猫 提交于 2021-02-20 06:29:17

问题


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 ?


回答1:


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




回答2:


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.




回答3:


This sounds very odd. Firstly if the code works for a time, as you say, the file must be there. Secondly, it is rare for a JVM to unload a class from memory once it has been used. Some JVMs will do it in tight memory situations or as part of a GC, but as an optimisation they normally stick around.

My only guess is you are using the JVM in a situation where ClassLoaders are changing. If you are using Netbeans (especially) but I think also eclipse, then if you partially recompile the code then classloaders might not match. Is this running within an IDE?

An alternative is a ClassLoader changing. If you re-release to a running webserver or application server, then an old class will not have a matching classloader for the new instance. The ClassLoader may not be able to find the old version, even though the file is there. Are you re-releasing to an Application/Webserver?

Finally, I guess this might be possible with Serialization. If the class is Serializable, and the serialVersionUIDs don't match I guess this might be able to happen. Are you doing any object serialisation here?



来源:https://stackoverflow.com/questions/5976563/java-lang-noclassdeffounderror-in-anonymous-inner-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!