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/ (at line 0)
[javac]     ^
[javac] Internal compiler error
[javac] java.lang.NullPointerException
[javac]     at org.eclipse.jdt.internal.compiler.ast.SingleTypeReference.getTypeBinding(
[javac]     at org.eclipse.jdt.internal.compiler.ast.TypeReference.internalResolveType(
[javac]     at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(
[javac]     at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(
[javac]     at org.eclipse.jdt.internal.compiler.ast.Annotation.resolveType(
[javac]     at org.eclipse.jdt.internal.compiler.ast.ASTNode.resolveAnnotations(
[javac]     at org.eclipse.jdt.internal.compiler.apt.dispatch.AnnotationDiscoveryVisitor.resolveAnnotations(
[javac]     at org.eclipse.jdt.internal.compiler.apt.dispatch.AnnotationDiscoveryVisitor.visit(
[javac]     at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.traverse(
[javac]     at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.traverse(
[javac]     at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundEnvImpl.(
[javac]     at org.eclipse.jdt.internal.compiler.apt.dispatch.BaseAnnotationProcessorManager.processAnnotations(
[javac]     at org.eclipse.jdt.internal.compiler.Compiler.processAnnotations(
[javac]     at org.eclipse.jdt.internal.compiler.Compiler.compile(
[javac]     at org.eclipse.jdt.internal.compiler.batch.Main.performCompilation(
[javac]     at org.eclipse.jdt.internal.compiler.batch.Main.compile(
[javac]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[javac]     at sun.reflect.NativeMethodAccessorImpl.invoke(
[javac]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(
[javac]     at java.lang.reflect.Method.invoke(
[javac]     at org.eclipse.jdt.core.JDTCompilerAdapter.execute(

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