Reputation: 33959
When pre-compiling JSPs with the Jasper compiler (using Tomcat), and then the Java compiler I see javac
warnings like this (I have javac
's -Xlint
flag enabled):
warning: [unchecked] unchecked call to add(E) as a member of the raw type java.util.List
_jspx_dependants.add("/some-jsp.jspf");
Now, it's "just a warning," but I like clean builds, so naturally I want to get rid of the warning. Sure, I could turn -Xlint
off for JSP compilation, but -Xlint
is good stuff, so it stays.
In this example warning, the problem is that generic syntax isn't used. Instead of List<String>
, we have only List
. I realize that the good folks who write Jasper have to cater to those unfortunate souls who remain locked in a pre-Java5 world. That's fine, but why should I have to suffer these warnings?
Is there some well-known way to eliminate javac warnings caused by the Java source code created by the Jasper JSP compiler? I'm not interested in an IDE-specific solution (though that would be a partial solution for some people who use the particular IDE). I'm looking for a generally applicable solution.
A scan of the Jasper source code didn't reveal any "Java 5+" switches that would cause generic syntax emission. In fact, on the contrary I found this:
apache-tomcat-6.0.18-src/java/org/apache/jasper/compiler/Generator.java:494: out.printin("_jspx_dependants = new java.util.ArrayList(");
which clearly shows the hardcoded code bereft of any hope for injection of elegant generic syntax.
Upvotes: 2
Views: 1275
Reputation: 33959
I'm using an Ant-based build. My current solution to this problem is to edit the offending Jasper generated Java code in-place with the following Ant filtering code:
<move todir="WEB-INF/src">
<fileset dir="WEB-INF/src"/>
<globmapper from="*.java"
to="*.java.foo"/>
<filterchain>
<tokenfilter>
<replacestring from="private static java.util.List _jspx_dependants;"
to="private static java.util.List<String> _jspx_dependants;"/>
<replacestring from="_jspx_dependants = new java.util.ArrayList"
to="_jspx_dependants = new java.util.ArrayList<String>"/>
<replaceregex pattern="public final class (.*) extends org.apache.jasper.runtime.HttpJspBase"
replace="@SuppressWarnings("serial")
public final class \1 extends org.apache.jasper.runtime.HttpJspBase"/>
<replacestring from="(PageContext)_jspx_page_context"
to="_jspx_page_context"/>
</tokenfilter>
</filterchain>
</move>
<move todir="WEB-INF/src" overwrite="true">
<fileset dir="WEB-INF/src"/>
<globmapper from="*.java.foo" to="*.java"/>
</move>
Please see this question to understand the "double move."
Upvotes: 0
Reputation: 112386
Disable the warnings you know are there and don't care about with:
-Xlint:-xxx
Disable warning xxx, where xxx is one of the warning names supported for -Xlint:xxx, below.
See here.
Upvotes: 1