java.lang.IllegalStateException: endPosTable already set

时间:2016-04-04 17:06:13

标签: compiler-errors java-8 maven-2 dagger-2

Trying to build an alexa (amazon:echo) skills set. At the same time, trying to use this experience as a learning testbed for dependency injection through dagger 2. However, building the package using maven-2 cmd:

mvn assembly:assembly -DdescriptorId=jar-with-dependencies package'. 

to generate a zip jar with the complete dependencies produces the following exception trace:

[INFO] ------------------------------------------------------------------------
[INFO] Building Echo Device Client 1.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ echo-device-client ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/apil.tamang/Dropbox/Git/echo-device-client/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ echo-device-client ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 46 source files to /Users/apil.tamang/Dropbox/Git/echo-device-client/target/classes
An exception has occurred in the compiler (1.8.0_60). Please file a bug at the Java Bug Database (http://bugreport.java.com/bugreport/) after checking the database 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)

The initial compilation happens fine, and all tests are run and successfully executed. I feel like it is during 'linking' the dependencies that things go south. Please take a look at this file to see the console output during the build.

My question is if it's worth a shot to try generate the dependencies using a different way. I don't know much about maven for that purpose. Is there a patch or something out there that can be used? Do you think it's even possible to come up with a workaround? I would like to be able to continue to use the dagger 2 framework for building this project.

5 个答案:

答案 0 :(得分:13)

错误报告JDK-8067747中描述了该问题:

(Jan Lahoda的

  

据我所知,这个错误有两个方面:

     
      
  1. 它因异常而崩溃的javac错误。我正在研究这个问题,但是请注意,当修复输入时,javac不会编译输入,它会从Filer中抛出一个适当的异常(见下文)。

  2.   
  3. 似乎是一个maven bug:当项目使用“clean install”编译时,注释处理器将生成一个源文件到“target / generated-sources / annotations”。当增量编译完成时,这个生成的文件作为输入传递给javac,注释处理器将尝试再次生成它,这是不允许的。

  4.   

这意味着当maven bug修复后,One or more errors occurred while processing template 'Entity.tt'. error : An exception was thrown while trying to compile the transformation code. The following Exception was thrown: System.ArgumentException: Empty path name is not legal. at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at System.IO.File.OpenRead(String path) at Roslyn.Utilities.FileUtilities.OpenFileStream(String path) at Microsoft.CodeAnalysis.MetadataReference.CreateFromFile(String path, MetadataReferenceProperties properties, DocumentationProvider documentation) at Microsoft.VisualStudio.TextTemplating.CompilerBridge.<>c.<.ctor>b__15_0(String x) at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext() at System.Linq.Enumerable.<UnionIterator>d__66`1.MoveNext() at System.Linq.Enumerable.<UnionIterator>d__66`1.MoveNext() at System.Linq.Buffer`1..ctor(IEnumerable`1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source) at System.Collections.Immutable.ImmutableArray.CreateRange[T](IEnumerable`1 items) at Microsoft.CodeAnalysis.ImmutableArrayExtensions.AsImmutableOrEmpty[T](IEnumerable`1 items) at Microsoft.CodeAnalysis.Compilation.ValidateReferences[T](IEnumerable`1 references) at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.WithReferences(IEnumerable`1 references) at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.CommonWithReferences(IEnumerable`1 newReferences) at Microsoft.VisualStudio.TextTemplating.CompilerBridge.PrepareNewCompilation() at Microsoft.VisualStudio.TextTemplating.CompilerBridge.Compile() at Microsoft.VisualStudio.TextTemplating.TransformationRunner.Compile(String source, String inputFile, IEnumerable`1 references, Boolean debug, SupportedLanguage language, String compilerOptions) 报告问题的错误与不适当的异常变得无关紧要。但是,考虑到Maven 2生命终结的实际日期,我怀疑你可以找到它的修复或补丁。

答案 1 :(得分:2)

正如this issue中所述,解决方法是禁用useIncrementalCompilation

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

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

答案 2 :(得分:0)

我不确定这是否有帮助。对于我的情况,我遇到了与open-jdk 8u91相同的问题,我安装了oracle-jdk,我可以在mvn clean compile之后运行该项目。问题是我必须在JDK之间切换每次运行并再次使用maven构建它。

编辑:经过两天的努力,我发现这是 mavenjdk之间不匹配的结果。我的IDE使用maven 3.0.5作为捆绑的maven。

解决方案:在IDE中,您应该将maven主目录从bundled maven更改为当前版本,例如 /usr/share/maven (对我来说当前版本是3.3.9)

答案 3 :(得分:0)

我遇到了与Maven和JDK 1.8.0_121构建和测试的项目相同的错误。在原始配置中,项目首先通过mvn clean进行清理,然后使用mvn install -projectSpecificParameters构建,最后使用单独的mvn install -otherProjectSpecificParameters进行测试。此配置导致问题中提到的错误。

更改阶段的顺序(首次测试然后构建)并在构建命令中添加clean目标以在测试后清除构建状态时,错误不再可再现。

答案 4 :(得分:0)

就我而言,这是在使用maven-processor-plugin插件生成JPA元数据文件时发生的。我使用特殊的Maven配置文件只生成了一次文件,并将它们添加到源文件夹中。

如错误报告中所述,当应重新编译现有文件时,会发生这种情况。解决方法是在执行maven-processor-plugin之前删除已编译的文件。例如:

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