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 241344 - "Initializer can be static" hint given when it is invalid and produces broken code.
Summary: "Initializer can be static" hint given when it is invalid and produces broken...
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:
: 241837 243363 245742 (view as bug list)
Depends on:
Blocks:
 
Reported: 2014-02-03 14:56 UTC by swpalmer
Modified: 2014-08-21 09:01 UTC (History)
3 users (show)

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-02-03 14:56:20 UTC
Product Version = NetBeans IDE Dev (Build 201402010001)
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-b69

I had an initializer block in an anonymous inner class implementing a MouseEvent handler:

	private void instalEventListener(final SplitPane splitPane) {
		splitPane.addEventFilter(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
			Timeline timeline;
			private double [] lastPos;
			private double [] hidePos;
			{
				int divs = splitPane.getDividers().size();
				lastPos = new double[divs];
				hidePos = new double[divs];
				hidePos[0] = 0;
				for (int i = 1; i < hidePos.length; i++) {
					hidePos[i] = 1;
				}
			}
			
			@Override
			public void handle(MouseEvent t) {
...

(EventHandler, MouseEvent, SplitPane and Timeline classes are from JavaFX)

The line below "private double [] hidePos;" was marked with the hint "Initializer can be static".  But it can't be static.  The initializer refers to instance member variables, e.g. "lastPos", "hidePos".  Invoking the hint places the "static" keyword in front of the opening { of the initializer and subsequently the code within is highlighted with error markers indicating "non-static variable lastPos cannot be referenced from a static context", etc.
Comment 1 Svata Dedic 2014-02-07 16:13:23 UTC
Fixed in jet-main#5727663a01ea
Comment 2 Quality Engineering 2014-02-14 02:54:15 UTC
Integrated into 'main-silver', will be available in build *201402140001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/5727663a01ea
User: Svata Dedic <sdedic@netbeans.org>
Log: #241344: enclosing type is correctly initialized for initializer blocks; referenced param of enclosing class' method
Comment 3 Jiri Prox 2014-02-14 08:54:42 UTC
*** Bug 241837 has been marked as a duplicate of this bug. ***
Comment 4 Svata Dedic 2014-07-18 11:02:17 UTC
*** Bug 245742 has been marked as a duplicate of this bug. ***
Comment 5 Svata Dedic 2014-08-21 09:01:24 UTC
*** Bug 243363 has been marked as a duplicate of this bug. ***