Bug 7455 - Build problems when instance variable name matches constructor parameter name and assignment to this.name in try block
Summary: Build problems when instance variable name matches constructor parameter name...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: All All
: P1 minor (vote)
Target Milestone: 2.0 M2   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-01-10 14:54 EST by Kevin J. Grittner CLA
Modified: 2002-02-13 13:43 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin J. Grittner CLA 2002-01-10 14:54:26 EST
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)
Comment 1 Philipe Mulet CLA 2002-01-11 07:26:06 EST
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.

Comment 2 Olivier Thomann CLA 2002-02-07 16:26:54 EST
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)
Comment 3 Philipe Mulet CLA 2002-02-08 06:55:37 EST
Fix was incomplete, revised fix (for both 1.0 and 2.0), added regresion test 
for both streams. 

Comment 4 Olivier Thomann CLA 2002-02-13 13:43:07 EST
Verified in rollup2.