Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.
Notice: I'm taking a break from blogging to focus on Atari Gamer . com, check it out!

NOTE: This article is 3 years or older so its information may no longer be relevant. Read on at your own discretion! Comments for this article have automatically been locked, refer to the FAQ for more details.
The Oracle Maven Plugin is great and provides very useful functionality like the ws-jwsc goal that compiles your JWS file into a deployable web service. However, in some situations I noticed that JWSC cannot handle unchecked generics. I did find a way to fix it so read on.

When this problem manifests, the plugin throws an exceptionally irrelevant exception that provides very little information. Below is what the exception looks like...
 JWSC Exception
An exception has occurred in the compiler (1.7.0_45). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you.
java.lang.IllegalAccessError: tried to access class com.sun.tools.javac.code.Kinds$1 from class com.sun.tools.javac.code.Kinds
at com.sun.tools.javac.code.Kinds.kindName(Kinds.java:146)
at com.sun.tools.javac.comp.Attr.checkMethod(Attr.java:2803)
at com.sun.tools.javac.comp.Attr.checkId(Attr.java:2579)
at com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:2363)
at com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:1677)
at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:431)
at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:418)
at com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:449)
at com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1521)
at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1321)
at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:431)
at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:418)
at com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:460)
at com.sun.tools.javac.comp.Attr.visitExec(Attr.java:1294)
at com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1167)
at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:431)
at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:418)
at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:480)
at com.sun.tools.javac.comp.Attr.attribStats(Attr.java:496)
at com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:918)
at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:781)
at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:431)
at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:418)
at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:480)
at com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:836)
at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:669)
at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:431)
at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:418)
at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:480)
at com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:3250)
at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:3173)
at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:3109)
at com.sun.tools.javac.comp.Attr.attrib(Attr.java:3083)
at com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1184)
at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:870)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:829)
at com.sun.tools.javac.main.Main.compile(Main.java:439)
at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:132)
at org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess(JavaxToolsCompiler.java:125)

So from that you'd think it's a compiler issue, but the problem actually lies in your own code. Specifically it is the use of unchecked generics that causes it.

To demonstrate, lets assume I have a class called TestClass that has a method called testMethod(). This method expects a List<T> as the input parameter. There is no other code in the method because its not necessary to show this problem.

package net.igorkromin;
public class TestClass {
public static <T> void testMethod(List<T> arg1) {
// do something

So far so good. There is nothing extraordinary in the code above (except that it doesn't do anything useful). Now lets say I wanted to make use of this class and its sole method somewhere in my web service code. Lets also say that I was lazy and didn't declare my List properly so my code ends up with an unchecked generic like this...
 Failing Java Code
List list = new ArrayList(); // <-- unchecked generic type List

The above will cause JWSC to fail. For some reason because testMethod() expects a List<T> and it gets a List instead, JWSC goes whacko.

Now if I declare my list variable with a qualified generic type like below, everything works as expected, no complaints from JWSC!
 Passing Java Code
List<Integer> list = new ArrayList<>();

The second version of the code is of course better in many ways, so I wouldn't necessarily call this a JWSC bug, however the exception that is being thrown could have been better or perhaps it should have been a warning saying that there is an unchecked type being used!


Skip down to comments...
A quick disclaimer...

Although I put in a great effort into researching all the topics I cover, mistakes can happen. If you spot something out of place, please do let me know.

All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle). Use of any information contained in this blog post/article is subject to this disclaimer.
comments powered by Disqus
Other posts you may like...