Skip to main content

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

Inline comments...

On Sun, Aug 23, 2015 at 9:05 PM, Barbara Tuchman <barbaratuchman@xxxxxxxxx> wrote:

~~~~~~~~~~ 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>( ~[core-3.1.1.jar:na]
        at org.apache.jasper.compiler.JDTJavaCompiler$1.findType( ~[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.

Per the JSP spec the Java support level is Java 6 (and it still is, even today).
Notice that Jetty 6 doesn't use Java itself to compile JSPs?
Jetty 6 is using the Eclipse JDT compiler.
Breaking spec to support Java 8 is handled by configuring to use Java and JavaC itself.


~~~~~~~~~~ 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

Jetty is a 100% modular web container.
Nothing is mandatory. (Not even the Server!)
There is no concept of "all", "minimum", or "everything". (these mean different things to different people).

You really should use some sort of build system.
You have many to choose from.
Would recommend: Apache Maven, Grails, or Apache Ant+Ivy.
Alternative build tooling: Apache Buildr, Groovy Grape, Scala SBT, or Leiningen

IntelliJ supports Apache Maven and Grails *very well*.
Once you decide what you need, you reference just that, and let the build tooling pull in what's relevant. (eg: you want jsp, so you use "org.eclipse.jetty:apache-jsp:{jetty-version}", and you'll wind up with the jars that you need, resolved for conflicts and build/compile vs test scopes)

I came across this web page
which mentions using a "jetty-all.jar" file to work around this problem.  So, I downloaded the latest stable one

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?)

You should not use jetty-all.jar.
Something we use to help people understand jetty in our documentation. (and limited in scope to support only this task)
It's not meant to be used from any real world project.

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

A web search found a similar issue described here:
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
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( ~[org.mortbay.jasper.apache-jsp-8.0.23.M1.jar:2.3]
        at org.apache.jasper.servlet.JspServletWrapper.service( ~[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>( ~[org.mortbay.jasper.apache-jsp-8.0.23.M1.jar:2.3]
        at org.apache.jasper.compiler.Validator.validateExDirectives( ~[org.mortbay.jasper.apache-jsp-8.0.23.M1.jar:2.3]

Indiscriminate copying of jar files is not going to help you.
Did you know that those 4 jar files provide you JSP (no JSTL) and will operate in the JSP spec/standard mode of Java 6? Just like Jetty 6.
Again, use Maven (or Grails) to obtain the correct jars, and then configure your desired environment correctly for Java 8 support.


~~~~~~~~~~ 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
    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

Step #5 is completely the wrong thing to do.
You now have many duplicate classes, from different versions of the same artifact.
You also now have many classes that are actually dangerous (from a security point of view) to run in production.
You also have all of the maven infrastructure (and 3rd party plugins) in your web server now.
Use Maven (or Grails) to get the appropriate set of jars that you need.


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( ~[apache-jsp-8.0.9.M3.jar:2.3]
        at org.apache.jasper.servlet.JspServletWrapper.service( ~[apache-jsp-8.0.9.M3.jar:2.3]
    Caused by: java.lang.NullPointerException: null
        at org.apache.jasper.compiler.Validator$ValidateVisitor.<init>( ~[apache-jsp-8.0.9.M3.jar:2.3]
        at org.apache.jasper.compiler.Validator.validateExDirectives( ~[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.

You are still using the JSP spec mandated Java 6 support.
The Eclipse JDT compiler is still in use.
Switch to using JavaC.

~~~~~~~~~~ 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):

This looks like your blog.
Its identical to what you are describing.
Why they didn't use this forum, or stackoverflow, i cannot comprehend.


    --this link, which reports what looks like the same problem, claims to have a solution, but hides it behind subscription access:  

This one isn't related to your problem.
This is a configuration issue in jboss.

    --this link, which reports what looks like the same problem, and whose solution was to correct a typo in a .tld file:

This one was a mistake in their tld definition.
Once fixed, it started to work for them.

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.


Most important recommendations:

  1. Don't flail.
  2. Understand the problem.
  3. Use Maven (or grails) to get the correct set of Jars that *you* need for your project.
  4. Don't include the eclipse jdt jar in your project (use exclusions with maven/grails)
  5. Look at the code for
    1. Configure for JavaC
    2. Setup context Attributes
    3. Setup InstanceManager
    4. Setup JettyJasperInitializer
    5. (and more, see the code)

Good luck,
- Joakim

Back to the top