Internal Compiler Error while building a liferay 6.1.10 plugin

Posted on 09/10/2015 by Charalampos Chrysikopoulos

The problem
I recently encounter a strange problem on a functioning project. I made a svn branch of it, and then I tried to build the branch in the same sdk, but it failed. And it failled with an internal compiler error: NullPointerException. This was very strange. The exact error was:

[javac] 1. ERROR in /XXXX/liferay-plugins-sdk-6.1.10-ee-ga1/portlets/XXXX-portlet/docroot/WEB-INF/src/XXXX/ObjectFactory.java (at line 0)
[javac]
[javac]     ^
[javac] Internal compiler error
[javac] java.lang.NullPointerException
[javac]     at org.eclipse.jdt.internal.compiler.ast.SingleTypeReference.getTypeBinding(SingleTypeReference.java:44)
[javac]     at org.eclipse.jdt.internal.compiler.ast.TypeReference.internalResolveType(TypeReference.java:130)
[javac]     at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:197)
[javac]     at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:193)
[javac]     at org.eclipse.jdt.internal.compiler.ast.Annotation.resolveType(Annotation.java:231)
[javac]     at org.eclipse.jdt.internal.compiler.ast.ASTNode.resolveAnnotations(ASTNode.java:594)
[javac]     at org.eclipse.jdt.internal.compiler.apt.dispatch.AnnotationDiscoveryVisitor.resolveAnnotations(AnnotationDiscoveryVisitor.java:143)
[javac]     at org.eclipse.jdt.internal.compiler.apt.dispatch.AnnotationDiscoveryVisitor.visit(AnnotationDiscoveryVisitor.java:131)
[javac]     at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.traverse(TypeDeclaration.java:1198)
[javac]     at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.traverse(CompilationUnitDeclaration.java:687)
[javac]     at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundEnvImpl.(RoundEnvImpl.java:56)
[javac]     at org.eclipse.jdt.internal.compiler.apt.dispatch.BaseAnnotationProcessorManager.processAnnotations(BaseAnnotationProcessorManager.java:148)
[javac]     at org.eclipse.jdt.internal.compiler.Compiler.processAnnotations(Compiler.java:794)
[javac]     at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:423)
[javac]     at org.eclipse.jdt.internal.compiler.batch.Main.performCompilation(Main.java:3543)
[javac]     at org.eclipse.jdt.internal.compiler.batch.Main.compile(Main.java:1645)
[javac]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[javac]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[javac]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[javac]     at java.lang.reflect.Method.invoke(Method.java:597)
[javac]     at org.eclipse.jdt.core.JDTCompilerAdapter.execute(JDTCompilerAdapter.java:79)

NullPointerException and at line 0? Where should I search...? The liferay sdk is using per default the eclipse java compiler, which is the ecj.jar included in the lib dir of the sdk directory. And it seems to be a very old version.
Even the eclipse guys didn't know about it.

A simple update of the ecj.jar to the newest version was the solution of the problem of the compilation error.

The solution
Updating the ecj.jar in the liferay SDK includes the following steps:

  1. replace the file ecj.jar with the newest one,
  2. delete the ecj.jar from the ant lib directory,
  3. run the ant war task to copy the new ecj.jar int the ant lib directory (it will seem like an error, but it isn't),
  4. run the ant war again to build your plugin.
But...
Although the problem is solved I am not happy. Something is still bothering me: Why did the original version of the same plugin compile without errors? It had the same code/files. If someone has an idea, please tell me.
This entry was posted in Liferay and tagged compilation, ecj, liferay 6.1 by Charalampos Chrysikopoulos