eclipse编译错误:AST创建期间JDT Core出错

时间:2015-03-09 11:48:53

标签: java eclipse compiler-errors

在更新到最新的eclipse Luna和Java JDK版本之后,我突然在我们的一个类的包声明中标记了以下eclipse编译器错误:

问题视图中的事件详细信息显示以下信息:

eclipse.buildId=4.4.2.M20150204-1700
java.version=1.8.0_40
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=de_DE
Framework arguments:  -product org.eclipse.epp.package.java.product -showlocation
Command-line arguments:  -os win32 -ws win32 -arch x86 -product org.eclipse.epp.package.java.product -clean -showlocation -data C:\workspaces\blub

This is a continuation of log file C:\workspaces\blub\.metadata\.bak_0.log
Created Time: 2015-03-09 11:43:33.242

org.eclipse.jdt.ui
Error
Mon Mar 09 11:50:01 CET 2015
Problems occurred when invoking code from plug-in: "org.eclipse.jdt.ui".

java.lang.NullPointerException
    at org.eclipse.jdt.internal.compiler.ast.SingleNameReference.analyseCode(SingleNameReference.java:186)
    at org.eclipse.jdt.internal.compiler.ast.MessageSend.analyseCode(MessageSend.java:125)
    at org.eclipse.jdt.internal.compiler.ast.LocalDeclaration.analyseCode(LocalDeclaration.java:87)
    at org.eclipse.jdt.internal.compiler.ast.Block.analyseCode(Block.java:43)
    at org.eclipse.jdt.internal.compiler.ast.LambdaExpression.analyseCode(LambdaExpression.java:508)
    at org.eclipse.jdt.internal.compiler.ast.MessageSend.analyseCode(MessageSend.java:175)
    at org.eclipse.jdt.internal.compiler.ast.Block.analyseCode(Block.java:43)
    at org.eclipse.jdt.internal.compiler.ast.IfStatement.analyseCode(IfStatement.java:105)
    at org.eclipse.jdt.internal.compiler.ast.Block.analyseCode(Block.java:43)
    at org.eclipse.jdt.internal.compiler.ast.WhileStatement.analyseCode(WhileStatement.java:120)
    at org.eclipse.jdt.internal.compiler.ast.Block.analyseCode(Block.java:43)
    at org.eclipse.jdt.internal.compiler.ast.LambdaExpression.analyseCode(LambdaExpression.java:508)
    at org.eclipse.jdt.internal.compiler.ast.SingleNameReference.analyseAssignment(SingleNameReference.java:105)
    at org.eclipse.jdt.internal.compiler.ast.Assignment.analyseCode(Assignment.java:79)
    at org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration.analyseCode(ConstructorDeclaration.java:176)
    at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.internalAnalyseCode(TypeDeclaration.java:733)
    at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.analyseCode(TypeDeclaration.java:261)
    at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.analyseCode(CompilationUnitDeclaration.java:118)
    at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:1207)
    at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:689)
    at org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:1183)
    at org.eclipse.jdt.core.dom.ASTParser.createAST(ASTParser.java:809)
    at org.eclipse.jdt.internal.ui.javaeditor.ASTProvider$1.run(ASTProvider.java:544)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.jdt.internal.ui.javaeditor.ASTProvider.createAST(ASTProvider.java:537)
    at org.eclipse.jdt.internal.ui.javaeditor.ASTProvider.getAST(ASTProvider.java:480)
    at org.eclipse.jdt.ui.SharedASTProvider.getAST(SharedASTProvider.java:128)
    at org.eclipse.jdt.internal.ui.text.java.hover.NLSStringHover.internalGetHoverInfo(NLSStringHover.java:135)
    at org.eclipse.jdt.internal.ui.text.java.hover.NLSStringHover.getHoverInfo2(NLSStringHover.java:114)
    at org.eclipse.jdt.internal.ui.text.java.hover.BestMatchHover.getHoverInfo2(BestMatchHover.java:163)
    at org.eclipse.jdt.internal.ui.text.java.hover.BestMatchHover.getHoverInfo2(BestMatchHover.java:129)
    at org.eclipse.jdt.internal.ui.text.java.hover.JavaEditorTextHoverProxy.getHoverInfo2(JavaEditorTextHoverProxy.java:85)
    at org.eclipse.jface.text.TextViewerHoverManager$4.run(TextViewerHoverManager.java:166)

幸运的是,我能够从项目中提取一个小例子来重现这个错误。代码本身不再有意义,但它的有效java代码,它显示了eclipse编译器错误:

import java.util.List;
import java.util.Map;
import java.util.Objects;

import javafx.collections.ListChangeListener;
import javafx.scene.shape.Path;
import javafx.scene.shape.PathElement;

public class LogicalPathDriver
{
  private final ListChangeListener<PathElement> synchronizeLogicalPathWithElements;
  private final Path                            representation;

  private Map<PathElement, PathElement>         realToLogicalElementsMapping;

  public LogicalPathDriver()
  {
    this.representation = new Path();

    synchronizeLogicalPathWithElements = change ->
    {
      while ( change.next() )
      {
        if ( change.wasRemoved() )
        {
          final List<? extends PathElement> removed = change.getRemoved();
          removed.forEach( removedElement ->
          {
            final PathElement logicalElement = realToLogicalElementsMapping.get( removedElement );
            Objects.requireNonNull( change );
            representation.getElements().remove( logicalElement );
          } );
        }
      }
    };
  }
}

有一些解决方案可以解决这个问题:

  1. 使用匿名类而不是lambda。
  2. 将表示范围更改为局部变量。
  3. 评论forEach声明的内容。
  4. 在将此添加到eclipse bug跟踪器之前,我想确定,这是一个真正的错误,或者我在这里遗漏了什么。

0 个答案:

没有答案