JDK-8067747 : javac throws exception during compilation when annotation processing is enabled
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8u25
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2014-12-01
  • Updated: 2024-08-16
  • Resolved: 2017-01-26
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 10 JDK 9
10Fixed 9 b155Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b18)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Windows 8 64 bit

A DESCRIPTION OF THE PROBLEM :
Maven compilation with annotation processing enabled fails, if the target/generated-sources/metamodel directory is not empty.
If it's not empty, javac fails to compile.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create at least 1 JPA entity (@Entity) and a persistence unit
Configure maven to use an annotation processor (QueryDSL 3.6 or eclipseLink 2.5.2)  during compilation (both tested, giving the same exception)
run: mvn compile twice, without using mvn clean in between, i.e.
> mvn clean compile
> mvn compile


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
compilation succeeds both times
ACTUAL -
The first compilation succeeds. the second fails with an exception.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
[INFO] Compiling 108 source files to myproject\target\classes
An exception has occurred in the compiler (1.8.0_25). 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.IllegalStateException: endPosTable already set
        at com.sun.tools.javac.util.DiagnosticSource.setEndPosTable(DiagnosticSource.java:136)
        at com.sun.tools.javac.util.Log.setEndPosTable(Log.java:350)
        at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:667)
        at com.sun.tools.javac.main.JavaCompiler.parseFiles(JavaCompiler.java:950)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.<init>(JavacProcessingEnvironment.java:892)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.next(JavacProcessingEnvironment.java:921)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1187)
        at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
        at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856)
        at com.sun.tools.javac.main.Main.compile(Main.java:523)
        at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129)
        at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138)
        at org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess(JavaxToolsCompiler.java:125)
        at org.codehaus.plexus.compiler.javac.JavacCompiler.performCompile(JavacCompiler.java:169)
        at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:823)
        at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:129)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:347)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:582)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
SampleEntity.java:

@Entity
public class SampleEntity {
	@Id
	public long id;
	
	@Version
	public long version;
	
	public String name;
	
}

maven POM:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.test</groupId>
    <artifactId>mavenproject1</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>
    
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </properties>
	
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.2</version>
				<configuration>
					<encoding>${project.build.sourceEncoding}</encoding>
					<generatedSourcesDirectory>${basedir}/target/generated-sources/metamodel</generatedSourcesDirectory>
					<showWarnings>true</showWarnings>
					<optimize>true</optimize>
					<showDeprecation>true</showDeprecation>
					<compilerId>javac</compilerId>
					<!-- <verbose /> -->
					<annotationProcessors>
						<annotationProcessor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</annotationProcessor>
					</annotationProcessors>
				</configuration>
			</plugin>
		</plugins>
	</build>
	<dependencies>
		<dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
		<!-- Needed for annotation processing only -->
		<dependency>
			<groupId>com.mysema.querydsl</groupId>
			<artifactId>querydsl-apt</artifactId>
			<version>3.6.0</version>
			<classifier>jpa</classifier>
			<scope>provided</scope>
		</dependency>
    </dependencies>
</project>
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
none known


Comments
Hi Jan, we got around ~20 issues reported on 8. Do you have any plans to backport this to 8?
14-03-2017

URL: http://hg.openjdk.java.net/jdk9/jdk9/langtools/rev/3fdaf9e50f5c User: lana Date: 2017-02-01 21:14:23 +0000
01-02-2017

URL: http://hg.openjdk.java.net/jdk9/dev/langtools/rev/3fdaf9e50f5c User: jlahoda Date: 2017-01-26 13:19:03 +0000
26-01-2017

To my knowledge, there are two aspects to this bug: 1) the javac bug that it crashes with an exception. I am working on this, but please note that javac won't compile the input when this is fixed, it will throw an appropriate exception from the Filer (see below). 2) what appears to be a maven bug: when the project is compiled with "clean install", an annotation processor will generate a source file into "target/generated-sources/annotations". When the incremental compilation is done, this generated file is passed to javac as an input, and the annotation processor will try to generate it again, which is not allowed. Please see: https://docs.oracle.com/javase/8/docs/api/javax/annotation/processing/Filer.html In particular: {quote} During each run of an annotation processing tool, a file with a given pathname may be created only once. If that file already exists before the first attempt to create it, the old contents will be deleted. Any subsequent attempt to create the same file during a run will throw a FilerException, as will attempting to create both a class file and source file for the same type name or same package name. The initial inputs to the tool are considered to be created by the zeroth round; therefore, attempting to create a source or class file corresponding to one of those inputs will result in a FilerException. {quote}
01-12-2015

This issue affects JMH users, as in: http://mail.openjdk.java.net/pipermail/jmh-dev/2015-August/002024.html
26-08-2015

This issue may be a duplicate of JDK-6462781.
10-01-2015

Seems to be duplicate of JDK-8062800 (although there is a better reproducible case here).
17-12-2014

Received attached project files from the user with following information: To reproduce the bug, execute: mvn clean mvn package mvn pacakge OS: MS Windows 7, 64bit. JAVA: JDK1.8.0_25, 64bit Maven: 3.2 On NetBeans received error "Pluginresolutionexception" and couldn't continue.
17-12-2014