我对此完全不知所措 - 更新了我的Java(到版本8,构建91),现在我的Groovy项目在早期开发阶段根本无法运行。 (查看答案更新是同时发生的)
BUG! exception in phase 'semantic analysis' in source unit 'Simul.groovy' unexpected NullpointerException
Caused by: java.lang.NullPointerException
以下是一段代码示例:
package simul
class Simulation {
def globalMemory
def signalNetwork
def processors
def blueTree
def coreArray
def outputDevice
def endian
def coreCount
static CORE_COUNT = 256
static TOTAL_MEM_SIZE = 0x100000000
static DEFAULT_ENDIAN = 0
static LOCAL_MEM_SIZE = 16
static LOCAL_MEM_START = 0xA0000000
Simulation(def cores = this.CORE_COUNT, def memSize = this.TOTAL_MEM_SIZE,
def endianess = this.DEFAULT_ENDIAN)
{
//0 for little endian, 1 for big endian
endian = endianess
globalMemory = new MemoryArray(this, memSize, 0)
coreCount = cores
}
}
def stuff = new Simulation()
stuff.coreArray = []
for (coreNumb in 1..stuff.coreCount) {
stuff.coreArray << new Core(stuff, coreNumb - 1)
}
Eclipse只标记包行上的错误(并对其他类文件执行相同的操作)。
我认为这是由Java更新引起的问题,但我发现没有其他人在线引用此问题(不幸的是,由于DNS问题,Groovy电子邮件列表似乎不可用)。
任何线索?
更新
如果我尝试自己运行其中一个文件,例如 groovyConsole Simul.groovy
,它将执行,但然后抱怨它无法看到包中的其他文件。事实上,如果我更改了Simul.groovy文件的包名,我可以在IDE中执行相同的操作(并且此错误也会在ggts中重复)。但是如果我尝试使用正确指定的包名称编译/运行代码,则此BUG失败!错误。
(这意味着问题类似 - 在症状方面 - 对此:https://answers.atlassian.com/questions/327479/scriptrunner-bug-exception-in-phase-semantic-analysis-in-source-unit-script40-groovy-bundle-is-uninstalled)
这是堆栈跟踪:
BUG! exception in phase 'semantic analysis' in source unit '/Users/adrian/groovy_stuff/simul/src/simul/Simul.groovy' unexpected NullpointerException
at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1226)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:651)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:629)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:606)
at org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitDeclaration.processToPhase(GroovyCompilationUnitDeclaration.java:201)
at org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitDeclaration.resolve(GroovyCompilationUnitDeclaration.java:2206)
at org.eclipse.jdt.internal.compiler.Compiler.resolve(Compiler.java:1084)
at org.eclipse.jdt.internal.compiler.Compiler.resolve(Compiler.java:1129)
at org.eclipse.jdt.internal.core.CompilationUnitProblemFinder.process(CompilationUnitProblemFinder.java:215)
at org.eclipse.jdt.internal.core.CompilationUnitProblemFinder.process(CompilationUnitProblemFinder.java:281)
at org.codehaus.jdt.groovy.model.GroovyReconcileWorkingCopyOperation.makeConsistent(GroovyReconcileWorkingCopyOperation.java:80)
at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.executeOperation(ReconcileWorkingCopyOperation.java:90)
at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:729)
at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:789)
at org.codehaus.jdt.groovy.model.GroovyCompilationUnit.reconcile(GroovyCompilationUnit.java:440)
at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:126)
at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.access$0(JavaReconcilingStrategy.java:108)
at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy$1.run(JavaReconcilingStrategy.java:89)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:87)
at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:151)
at org.eclipse.jdt.internal.ui.text.CompositeReconcilingStrategy.reconcile(CompositeReconcilingStrategy.java:86)
at org.eclipse.jdt.internal.ui.text.JavaCompositeReconcilingStrategy.reconcile(JavaCompositeReconcilingStrategy.java:104)
at org.eclipse.jface.text.reconciler.MonoReconciler.process(MonoReconciler.java:77)
at org.eclipse.jface.text.reconciler.AbstractReconciler$BackgroundThread.run(AbstractReconciler.java:206)
Caused by: java.lang.NullPointerException
at org.codehaus.groovy.control.StaticVerifier$1.visitVariableExpression(StaticVerifier.java:84)
at org.codehaus.groovy.ast.expr.VariableExpression.visit(VariableExpression.java:70)
at org.codehaus.groovy.ast.CodeVisitorSupport.visitPropertyExpression(CodeVisitorSupport.java:251)
at org.codehaus.groovy.ast.expr.PropertyExpression.visit(PropertyExpression.java:55)
at org.codehaus.groovy.control.StaticVerifier.visitConstructorOrMethod(StaticVerifier.java:79)
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructor(ClassCodeVisitorSupport.java:121)
at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1214)
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:52)
at org.codehaus.groovy.control.StaticVerifier.visitClass(StaticVerifier.java:42)
at org.codehaus.groovy.control.CompilationUnit$13.call(CompilationUnit.java:235)
at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1221)
... 24 more
答案 0 :(得分:-1)
嗯,答案是我将this.STATIC_MEMBER
形式的类Simulation的静态成员称为类构造函数的参数。
由于this
此时并不存在(并且在任何情况下都是多余的),这确实会引发NullPointerException
,尽管它在这一点上被标记为高度混乱package
命令。