Bug 549092 - Unexpected 'The final local variable […] may already have been assigned' reported
Summary: Unexpected 'The final local variable […] may already have been assigned' repo...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2019-07-09 07:01 EDT by Wolfgang Illmeyer CLA
Modified: 2022-08-25 14:41 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Wolfgang Illmeyer CLA 2019-07-09 07:01:30 EDT
This will compile with javac (tested on openjdk 8) but not with Eclipse:

import java.net.URI;
import java.net.URISyntaxException;

public class EvilFinal {
	public URI doEvil() {
		final String test;
		try {
			return new URI("x");
		} catch (URISyntaxException e) {
			test = e.getMessage();
		} catch (RuntimeException e) {
			test = e.getClass().getName();
		}
		System.out.println(test);
		return null;
	}
}

It will complain in the second catch block, that »The final local variable test may already have been assigned«

The version dial won't let me select the JDT version eclipse reports:
    Eclipse Java Development Tools	3.17.0.v20190307-0500	org.eclipse.jdt.feature.group
Comment 1 Andrey Loskutov CLA 2019-07-09 07:05:45 EDT
Interesting. I see this also in 4.6.3 Eclipse, nothing new.
Comment 2 Stephan Herrmann CLA 2019-07-09 07:15:17 EDT
Thanks, I can reproduce all the way back to ECJ 3.0.2 (oldest jar I have on my disk).

Interestingly, also javac versions <= 1.7 complain:

EvilFinal.java:12: error: variable test might already have been assigned
                        test = e.getClass().getName();
                        ^
1 error


Need to figure out, if JLS has changed in this regard, or if that change in javac was a bug fix.
Comment 3 Manoj N Palat CLA 2019-08-27 01:22:02 EDT
Bulk move to 4.14
Comment 4 Stephan Herrmann CLA 2019-11-17 16:09:03 EST
Bulk move of unassigned bugs to 4.15
Comment 5 Stephan Herrmann CLA 2020-02-27 18:48:59 EST
Bulk move to 4.16
Comment 6 Stephan Herrmann CLA 2020-05-18 18:47:17 EDT
Bulk move of unassigned bugs to 4.17
Comment 7 Eclipse Genie CLA 2022-08-25 14:41:46 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.