Summary: | [1.5] NPE in java compiler | ||
---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Igor Fedorenko <igor> |
Component: | Core | Assignee: | Philipe Mulet <philippe_mulet> |
Status: | RESOLVED FIXED | QA Contact: | |
Severity: | normal | ||
Priority: | P3 | ||
Version: | 3.0 | ||
Target Milestone: | 3.1 M1 | ||
Hardware: | PC | ||
OS: | Windows 2000 | ||
Whiteboard: |
Description
Igor Fedorenko
2004-06-30 08:59:51 EDT
Fixed in HEAD. Constant propagation did not handle correctly duality of ParameterizedFieldBinding and original FieldBinding. Added regression test: GenericTypeTest#test216. Compiling the same code now results in ClassCastException !ENTRY org.eclipse.jdt.core 4 4 Jul 01, 2004 21:44:21.322 !MESSAGE Exception occurred during problem detection: !STACK 0 java.lang.ClassCastException at org.eclipse.jdt.internal.compiler.ast.FieldReference.getConstantFor(FieldReference.java:352) at org.eclipse.jdt.internal.compiler.ast.SingleNameReference.checkFieldAccess(SingleNameReference.java:163) at org.eclipse.jdt.internal.compiler.ast.SingleNameReference.resolveType(SingleNameReference.java:647) at org.eclipse.jdt.internal.compiler.ast.EqualExpression.resolveType(EqualExpression.java:504) at org.eclipse.jdt.internal.compiler.ast.ReturnStatement.resolve(ReturnStatement.java:214) at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolveStatements(AbstractMethodDeclaration.java:395) at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.resolveStatements(MethodDeclaration.java:134) at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolve(AbstractMethodDeclaration.java:373) at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:920) at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:969) at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.resolve(CompilationUnitDeclaration.java:280) at org.eclipse.jdt.internal.compiler.Compiler.resolve(Compiler.java:564) at org.eclipse.jdt.internal.core.CompilationUnitProblemFinder.process(CompilationUnitProblemFinder.java:176) at org.eclipse.jdt.internal.core.CompilationUnit.buildStructure(CompilationUnit.java:146) at org.eclipse.jdt.internal.core.Openable.generateInfos(Openable.java:183) at org.eclipse.jdt.internal.core.JavaElement.openWhenClosed(JavaElement.java:572) at org.eclipse.jdt.internal.core.CompilationUnit.makeConsistent(CompilationUnit.java:971) at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.executeOperation(ReconcileWorkingCopyOperation.java:58) at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:700) at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:739) at org.eclipse.jdt.internal.core.CompilationUnit.reconcile(CompilationUnit.java:1097) at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:88) at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:129) at org.eclipse.jdt.internal.ui.text.CompositeReconcilingStrategy.reconcile(CompositeReconcilingStrategy.java:86) at org.eclipse.jdt.internal.ui.text.JavaCompositeReconcilingStrategy.reconcile(JavaCompositeReconcilingStrategy.java:96) at org.eclipse.jface.text.reconciler.MonoReconciler.process(MonoReconciler.java:75) at org.eclipse.jdt.internal.ui.text.JavaReconciler.process(JavaReconciler.java:315) at org.eclipse.jface.text.reconciler.AbstractReconciler$BackgroundThread.run(AbstractReconciler.java:204) Igor - are you sure you took the proper fix from HEAD ? Can no longer reproduce, and regression test is passing. Just checked that my org.eclipse.jdt.core is in sync with HEAD and yet I am getting the ClassCastException. I have two workspaces -- one for cheetah itself and another for jdk1.5 based development -- and start latter from former. I'll try to run the regression tests later today or tomorrow to see if I can reproduce the problem. FieldReference#getConstantFor cannot handle bindings to final members of parametrized classes. At around line 352 it assumes that all binding.declaringClass are instanced of SourceTypeBinding which is not the case for parametrized types because ParameterizedTypeBinding is not subclass of SourceTypeBinding. Here is a slightly modified version of my original example that demostrates the problem (the only difference from original is "final" qualifier of member "o"). ================================== package test.cheetah; public class G<E> { protected final Object o; } ================================== package test.cheetah; public class NG extends G { public boolean test() { return o == null; } } ================================== PS: am I right that a field has to be both final and static to be a constant? Why can't you use "!binding.isFinal() || !binding.isStatic()" condition instead of "!binding.isFinal()" at line 334? Constant fields do not need to be static. I had indeed missed handling the final scenario. Added support and regression test GenericTypeTest#test224. |