boonproject / boon

Simple opinionated Java for the novice to expert level Java Programmer. Low Ceremony. High Productivity.
http://richardhightower.github.io/site/Boon/Welcome.html
Apache License 2.0
520 stars 102 forks source link

Sys.detectContainer can crash with ClassFormatError #317

Closed slandelle closed 9 years ago

slandelle commented 9 years ago

Binaries in "javax/javaee-api" jar are especially constructed so to that the classes it contains won't load and crash with a ClassFormatError.

So if this jar is in the classpath, Sys will crash as it only traps ClassNotFoundException. I say Sys should trap ClassFormatError too.

java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/servlet/http/HttpServlet
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at org.boon.core.Sys.detectContainer(Sys.java:207)
    at org.boon.core.Sys.<clinit>(Sys.java:196)
    at org.boon.core.value.LazyValueMap.buildMap(LazyValueMap.java:225)
slandelle commented 9 years ago

@RichardHightower I can provide a PR if you agree with the suggested fix :-)

slandelle commented 9 years ago

It was reported that javax.javaee-api version 7.0 crashes with a different Exception: java.util.MissingResourceException: Can't find bundle for base name javax.servlet.LocalStrings, locale pt_BR

IMO, the best solution is to catch Throwable here.

RichardHightower commented 9 years ago

I agree.

RichardHightower commented 9 years ago

I accept and thank you for doing this.