Wednesday, September 03, 2008

java.CompilerError when running RMIC

The other day I was trying out a Java RMI program in connection to an assignment. Let me be very clear here: I really like Java as it was one of my first proper programming languages (mind you, I am talking here circa 1999-2000 when Java-fever hadn't caught up) and I am a big fan of its elegance. The only turn-off which made me head towards Microsoft's direction was the lack of a proper, Visual Studio-league IDE for Java in those days. Much water has passed under the bridge, and there are many better IDEs for Java now, like Eclipse and NetBeans, but the curse still remains. (You might also want to give JCreator a shot, one of my favorite Java editing tools)

So back to where I was, trying RMI. I made a simple interface class, which compiled fine, and then an implementation class, which compiled fine in itself too. Then I had to run RMIC on one of the classes (which I tried doing from command line, since I am not sure how NetBeans handles it), and plop, I got a java.CompilerError stating that something has gone horribly wrong and the compiler is now mangled, and that I am supposed to file a bug report. Something like this (extra line-breaks have been added for readability):

error: An error has occurred in the compiler; 
please file a bug report (http://java.sun.com/cgi-bin/bugreport.cgi).
1 error
----------log:rmic(7/491)----------
sun.tools.java.CompilerError: mangle NItem1Impl     javasoft$sqe$tests$api$java$rmi$Naming$NItem2Impl     javasoft$sqe$tests$api$java$rmi$Naming$NItem3Impl     javasoft$sqe$tests$api$java$rmi$Naming$NItem4Impl
at sun.tools.java.Type.mangleInnerType(Type.java)
at sun.tools.java.Type.tClass(Type.java)
at sun.tools.java.ClassDeclaration.(ClassDeclaration.java)
at sun.rmi.rmic.Main.doCompile(Main.java)
at sun.rmi.rmic.Main.compile(Main.java)
at sun.rmi.rmic.Main.main(Main.java)

Undaunted, I ran a Google search for the error which lead me to this bug report. Mind you, there is no solution in there. I figured the solution out myself. You just have to make sure that the jdk/bin directory is in your PATH variable (I am talking about Windows), and then compile the class from the command line from the class's directory. For example, earlier I was trying to run:
C:\Sun\SDK\jdk\bin>rmic 
"C:\Documents and Settings\uxuf\RMITest\build\RMIImpl"
but this threw an error everytime, so after setting the path variable (through System Properties->Advanced->Environment Variables) I found out that I had to pass the parameter to rmic without the quotes, which automatically means without any spaces :) and became something like:
C:\Documents and Settings\uxuf\RMITest\build>rmic RMIImpl
So if you are stuck in a similar situation, when no solution to that stupid error is in sight, try out rmic from the directory which contains the class. It worked for me!

1 comment:

Yvette said...

Thanks for writing this.