java.lang.IllegalStateException: endPosTable already set

泪湿孤枕 提交于 2019-12-01 02:33:39

The issue is described in the bug report JDK-8067747:

(by Jan Lahoda)

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.

This implies that when the maven bug is fixed, javac’s bug of reporting the problem with an inappropriate exception becomes irrelevant. However, given the actual date of Maven 2’s end-of-life, I doubt that you can expect to find a fix or patch for it.

As explained in this issue, a workaround is to disable useIncrementalCompilation:

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>

    <configuration>
        <useIncrementalCompilation>false</useIncrementalCompilation>
    </configuration>
</plugin>

I'm not sure if this can help. For my case, I had the same problem with open-jdk 8u91, I installed oracle-jdk and I could run the project after mvn clean compile. The problem was I must switched between JDKs for each run and building it once again with maven.

EDIT: after struggling about two days with it I found it is a result of mismatch between maven and jdk. My IDE used maven 3.0.5 as bundled maven.

Solution: In your IDE you should change your maven home directory from bundled maven to your current version for example /usr/share/maven. ( for me current version was 3.3.9)

I have encountered the same error with a project that was built and tested by Maven and JDK 1.8.0_121. In the original configuration the project was first cleaned via mvn clean, then built using mvn install -projectSpecificParameters and finally tested with a separate mvn install -otherProjectSpecificParameters. This configuration resulted in the error mentioned in the question.

After changing the order of the stages (first testing and then building) and adding a clean goal to the build command to clean up the built state after the tests the error was not reproducible anymore.

In my case this happened while generating JPA metadata files with the maven-processor-plugin plug-in. I produced the files only once with a special Maven profile and added them to the source folder.

As noted in the bug report this happens when an existing file should compiled again. The solution is the delete the compiled files before the maven-processor-plugin execution. E.g.:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-clean-plugin</artifactId>
    <executions>
        <execution>
            <id>clean-jpa-model</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>clean</goal>
            </goals>
            <configuration>
                <filesets>
                    <fileset>
                        <directory>
                            ${project.basedir}/src/main/java
                        </directory>
                        <includes>
                            <include>**/model/*_.java</include>
                        </includes>
                    </fileset>
                </filesets>
                <excludeDefaultDirectories>true</excludeDefaultDirectories>
            </configuration>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.0</version>
    <executions>
        <!--precompilation to find annotations and classed needed by the maven processor plugin for hibernate-jpamodelgen-->
        <execution>
            <id>compile-maven-processor</id>
            <goals>
                <goal>compile</goal>
            </goals>
            <phase>process-sources</phase>
            <configuration>
                <showDeprecation>false</showDeprecation>
                <showWarnings>false</showWarnings>
                <includes>
                    <include>**/model/*.java</include>
                </includes>
            </configuration>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.bsc.maven</groupId>
    <artifactId>maven-processor-plugin</artifactId>
    <version>3.3.3</version>
    <executions>
        <execution>
            <id>generate-jpa-model</id>
            <goals>
                <goal>process</goal>
            </goals>
            <phase>generate-sources</phase>
            <configuration>
                <includes>
                    <include>**/model/*.java</include>
                </includes>
                <processors> 
                    <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
                </processors>
                    <outputDirectory>${project.basedir}/src/main/java</outputDirectory>
            </configuration>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-jpamodelgen</artifactId>
            <version>${hibernate.version}</version>
            <scope>runtime</scope>
        </dependency>
    </dependencies>
</plugin>    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!