Community
Participate
Working Groups
Build problems when there is an instance variable name which matches a constructor parameter name and assignment is made to this.name in a try block finally clause. This class shows the problem: public final class TableData { public final String name; public TableData(String name) { try {} finally { this.name = name; } } } The Build Problems dialog shows with "Build problems" as the description. Pressing the <<Details button shows: --------------------------------------------------------- Errors during build. org.eclipse.jdt.internal.compiler.ast.FieldReference --------------------------------------------------------- FROM THE .log FILE: =================== Log: Thu Jan 10 13:29:36 CST 2002 2 org.eclipse.core.resources 2 Problems occurred when invoking code from plug-in: org.eclipse.core.resources. java.lang.ClassCastException: org.eclipse.jdt.internal.compiler.ast.FieldReference at org.eclipse.jdt.internal.compiler.flow.FinallyFlowContext.complainOnRedundantFi nalAssignments(FinallyFlowContext.java(Compiled Code)) at org.eclipse.jdt.internal.compiler.ast.TryStatement.analyseCode(TryStatement.jav a(Compiled Code)) at org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration.analyseCode(Constr uctorDeclaration.java(Compiled Code)) at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.analyseCode(TypeDeclarati on.java(Compiled Code)) at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.analyseCode(Co mpilationUnitDeclaration.java(Compiled Code)) at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java(Compiled Code)) at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java(Compiled Code)) at org.eclipse.jdt.internal.core.newbuilder.AbstractImageBuilder.compile(AbstractI mageBuilder.java:211) at org.eclipse.jdt.internal.core.newbuilder.AbstractImageBuilder.compile(AbstractI mageBuilder.java(Compiled Code)) at org.eclipse.jdt.internal.core.newbuilder.BatchImageBuilder.build(BatchImageBuil der.java:47) at org.eclipse.jdt.internal.core.newbuilder.JavaBuilder.buildAll(JavaBuilder.java: 113) at org.eclipse.jdt.internal.core.newbuilder.JavaBuilder.build(JavaBuilder.java:67) at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:356) at org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java(Co mpiled Code)) at org.eclipse.core.runtime.Platform.run(Platform.java(Compiled Code)) at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:114) at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:179) at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:189) at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:138) at org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java(Co mpiled Code)) at org.eclipse.core.runtime.Platform.run(Platform.java(Compiled Code)) at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:152) at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:214) at org.eclipse.core.internal.resources.Workspace.build(Workspace.java:130) at org.eclipse.ui.internal.GlobalBuildAction.build(GlobalBuildAction.java:57) at org.eclipse.ui.internal.GlobalBuildAction$1.run(GlobalBuildAction.java:141) at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.ja va:98)
Excellent find. Problem comes from the fact that (parsed) field references do not set the FIELD bit (as other name references do). As a result, the flow analysis is fooled into thinking it is dealing with a local variable. As a work-around, you can rename your argument, and assign the field without using the syntax 'this.name', but simply name. public final class TableData { public final String name; public TableData(String initName) { try {} finally { name = initName; } } } Will be fixed in next integration build.
Not fixed in 1.0. Running ConformTest.test110, I got: java.lang.ClassCastException: org.eclipse.jdt.internal.compiler.ast.FieldReference at org.eclipse.jdt.internal.compiler.flow.FinallyFlowContext.complainOnRedundantFinalAssignments(FinallyFlowContext.java:33) at org.eclipse.jdt.internal.compiler.ast.TryStatement.analyseCode(TryStatement.java:132) at org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration.analyseCode(ConstructorDeclaration.java:54) at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.analyseCode(TypeDeclaration.java:359) at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.analyseCode(CompilationUnitDeclaration.java:67) at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:379) at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:202) at org.eclipse.jdt.tests.compiler.regression.AbstractRegressionTest.runConformTest(AbstractRegressionTest.java:129) at org.eclipse.jdt.tests.compiler.regression.AbstractRegressionTest.runConformTest(AbstractRegressionTest.java:114) at org.eclipse.jdt.tests.compiler.regression.ConformTest.test110(ConformTest.java:3317) at junit.extensions.TestDecorator.basicRun(TestDecorator.java:22) at junit.extensions.TestDecorator.run(TestDecorator.java:28) at org.eclipse.jdt.tests.compiler.regression.RegressionTestSetup.run(RegressionTestSetup.java:38)
Fix was incomplete, revised fix (for both 1.0 and 2.0), added regresion test for both streams.
Verified in rollup2.