Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] embedded jetty 9 JSP: NullPointerException in org.apache.jasper.compiler.Validator



~~~~~~~~~~ Background ~~~~~~~~~~


An application at work uses embedded jetty 6 to support a single web page that we use to control a trading application.  This was written long before I joined, but I am stuck with maintaining it.  The web page uses 4 .jsp files to perform various actions.  (The web page is actually a flash page: when you click on certain buttons, it calls the associated .jsp to carry out the action.)  Each .jsp file is actually very simple; all are <= 1 KB in size.

I want to update the JDK on our prd server from 7 to the latest 8 release.

Testing in UAT reveals that everything works except for this web page.  In particular, with jetty 6 and JDK 8, I see this error in the logs:
    2015-08-21T17:19:26.183-0400 WARN [qtp0-0] - Compilation error
    org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException: null
        at org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader.<init>(ClassFileReader.java:298) ~[core-3.1.1.jar:na]
        at org.apache.jasper.compiler.JDTJavaCompiler$1.findType(JDTJavaCompiler.java:351) ~[jsp-2.1.jar:6.1.11]
        ...

Clearly, the ancient jdt compiler in jetty 6 cannot handle JDK 8 class files.  So, it is time to upgrade to a modern jetty version.

Unfortunately, when I try jetty 9, I get a NullPointerException in org.apache.jasper.compiler.Validator.  I cannot figure out why.  The rest of this email provides details.


~~~~~~~~~~ Step 1 ~~~~~~~~~~


The first issue that I was faced with in upgrading to a modern jetty is determining what jar files I need.  This is actually a nightmare, because:
    1) jetty 9 seems to have ~50 jars of its own, plus dependencies on ~50 more (see Step 3 below for proof)
    2) our project does not use maven or ant (just IntelliJ, as our project is fairly simple in regards to build requirements), and jetty seems to really want maven

I came across this web page
    https://www.eclipse.org/jetty/documentation/current/advanced-embedding.html
which mentions using a "jetty-all.jar" file to work around this problem.  So, I downloaded the latest stable one
    jetty-all-9.3.2.v20150730-uber.jar

I had to change some of my embedded code that launches the jetty server (e.g. to cope with new package names, slightly different API), but this was fairly straight forward.

Unfortunately, running my code failed: I see console logs like this:
    2015-08-21T16:50:48.165-0400 INFO [qtp889486595-18] {/} - No JSP support.  Check that JSP jars are in lib/jsp and that the JSP option has been specified to start.jar
(That log level probably ought to be ERROR, not INFO?)


~~~~~~~~~~ Step 2 ~~~~~~~~~~


A web search found a similar issue described here:
    https://stackoverflow.com/questions/26217143/embedded-jetty-server-no-jsp-support-for-did-not-find-org-apache-jasper-ser
Looks like the "all uber" jar file does not contain everything after all, contrary to its name.  In the link above,  Joakim Erdfelt eventually comments that
    "jetty-all.jar only exists as a teaching aid (referenced in the documentation), its not meant for production use"

Given that tip, since I had already downloaded a copy of the full 9.3.2.v20150730 distribution, I tried copying these additional 4 jars
    org.eclipse.jetty.apache-jsp-9.3.2.v20150730.jar
    org.eclipse.jetty.orbit.org.eclipse.jdt.core-3.8.2.v20130121.jar
    org.mortbay.jasper.apache-el-8.0.23.M1.jar
    org.mortbay.jasper.apache-jsp-8.0.23.M1.jar
from its lib/apache-jsp directory into my project's lib directory (where all its jar files live).

Running my code with these 4 additional jars now fails further on: I see this log:
    2015-08-21T16:54:30.933-0400 WARN [qtp1238959340-38] -
    org.apache.jasper.JasperException: Unable to compile class for JSP
        at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:600) ~[org.mortbay.jasper.apache-jsp-8.0.23.M1.jar:2.3]
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:363) ~[org.mortbay.jasper.apache-jsp-8.0.23.M1.jar:2.3]
        ...
    Caused by: java.lang.NullPointerException: null
        at org.apache.jasper.compiler.Validator$ValidateVisitor.<init>(Validator.java:515) ~[org.mortbay.jasper.apache-jsp-8.0.23.M1.jar:2.3]
        at org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1853) ~[org.mortbay.jasper.apache-jsp-8.0.23.M1.jar:2.3]
        ...


~~~~~~~~~~ Step 3 ~~~~~~~~~~


I got tired of guessing what jars my app needs, and decided on a simple brute force way to pull down everything:
    1) I deleted the 5 jetty jars described above from my app's lib directory
    2) I completely emptied my C:\Users\Sam\.m2\repository directory
    3) I downloaded the Embedded Jetty w/ JSP Support project
        https://github.com/jetty-project/embedded-jetty-jsp
    4) I built it (mvn clean package), started the server (mvn exec:exec), and verified that it worked in my browser (http://localhost:8080/)
    5) I copied every *.jar file from my C:\Users\Sam\.m2\repository directory (there are 100 of them!) into my app's lib directory

Running my code with these 100 jetty jars fails with a similar stack trace:
    2015-08-21T16:03:52.001-0400 WARN [qtp934275857-19] -
    org.apache.jasper.JasperException: Unable to compile class for JSP
        at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:579) ~[apache-jsp-8.0.9.M3.jar:2.3]
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357) ~[apache-jsp-8.0.9.M3.jar:2.3]
        ...
    Caused by: java.lang.NullPointerException: null
        at org.apache.jasper.compiler.Validator$ValidateVisitor.<init>(Validator.java:515) ~[apache-jsp-8.0.9.M3.jar:2.3]
        at org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1846) ~[apache-jsp-8.0.9.M3.jar:2.3]
        ...

This is probably essentially the same as Step 2 above: recall that Step 2 used jetty 9.3.2.v20150730, whereas the Embedded Jetty w/ JSP Support project still uses jetty-9.2.6.  So, that likely explains the different line numbers in the stack traces.


~~~~~~~~~~ Future work ~~~~~~~~~~


My conclusion after Step 3 is that I cannot be missing something on my classpath at this point.

Doing a more focused web search found:
    --this link, which reports what looks like the same problem (but has no solution):
        http://jspl598.blogspot.com/2015/03/while-accessing-jsps-in-jetty_13.html
    --this link, which reports what looks like the same problem, claims to have a solution, but hides it behind subscription access:
        https://access.redhat.com/solutions/315013  
    --this link, which reports what looks like the same problem, and whose solution was to correct a typo in a .tld file:
        http://www.coderanch.com/t/614308/JSP/java/EL-function

The solution in that final link above suggests that there is some bug in my code.

I do not have any .tld files, so the precise solution there is not relevant for me.

I quickly inspected my .jsp files, and see nothing obviously wrong.  Furthermore, I note that the .jsp files all worked under jetty 6.

SO, DOES ANYONE HAVE ANY SUGGESTIONS FOR WHERE I CAN LOOK TO DEBUG THIS?

Back to the top