This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 243478 - "Initializer can be static" hint replaces code with invalid code.
Summary: "Initializer can be static" hint replaces code with invalid code.
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 8.0
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-04-02 14:30 UTC by swpalmer
Modified: 2014-06-19 02:36 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description swpalmer 2014-04-02 14:30:08 UTC
Product Version = NetBeans IDE 8.0 (Build 201403101706)
Operating System = Windows 7 version 6.1 running on amd64
Java; VM; Vendor = 1.8.0
Runtime = Java HotSpot(TM) 64-Bit Server VM 25.0-b70


Given:

public final class A {	
	
	private static final Map<String, String> aMap = new LinkedHashMap<String, String>() {  
		{ put("a", "aaaaaa"); };   
		{ put("b", "bbbbbb"); };
		{ put("c", "cccccccc"); };
	};

	// rest of class doesn't matter
}

The "put" lines will have the "Initializer can be static" hint.  However if you click in the gutte and select "Make initializer static" the result is:

public final class A {	
	
	private static final Map<String, String> aMap = new LinkedHashMap<String, String>() {  
		static { put("a", "aaaaaa"); };     
		{ put("b", "bbbbbb"); };
		{ put("c", "cccccccc"); };
	};

	// rest of class doesn't matter
}

and the "static { put..." line is now highlighted with the error "Illegal static declaration in inner class..."  (Note that this class should never have been initialized in this way in the firsts place.  It doesn't need to be and shouldn't be an inner class, but still NB shouldn't offer to change it to illegal code.
Comment 1 Jiri Prox 2014-05-22 13:51:42 UTC
reproducible
Comment 2 Svata Dedic 2014-06-13 13:05:40 UTC
Fixed in jet-main#10299afe420b
Comment 3 Quality Engineering 2014-06-19 02:36:10 UTC
Integrated into 'main-silver', will be available in build *201406190001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/10299afe420b
User: Svata Dedic <sdedic@netbeans.org>
Log: #243478: fixed identification of generic types