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 262290 - Remove unnecessary return statement removes code
Summary: Remove unnecessary return statement removes code
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 8.2
Hardware: PC Windows 10 x64
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-06-01 02:12 UTC by _ gtzabari
Modified: 2016-07-19 01:42 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 _ gtzabari 2016-06-01 02:12:15 UTC
Product Version: NetBeans IDE Dev (Build 201605260002)
Java: 1.8.0_92; Java HotSpot(TM) 64-Bit Server VM 25.92-b14
Runtime: Java(TM) SE Runtime Environment 1.8.0_92-b14
System: Windows 10 version 10.0 running on amd64; Cp1252; en_CA (nb)
User directory: C:\Users\Gili\AppData\Roaming\NetBeans\dev
Cache directory: C:\Users\Gili\AppData\Local\NetBeans\Cache\dev

Given:

		public void clear()
		{
			return ConcurrentLinkedHashMap.this.clear();
		}

Netbeans flags the method body with "remove unnecessary return statement".
Invoking the hint removes the entire line. I am expecting it to remove "return" and leave "ConcurrentLinkedHashMap.this.clear();" unchanged.
Comment 1 Svata Dedic 2016-07-14 17:37:33 UTC
There are cases when the entire statement could be removed; the choice mainly depends on the user.

However removing 'return' could be quite tricky - not all expressions can be interpreted as statement, c.f. statements like
   return s.length() + 1;
   return empty ? s : null;
   return checkFoo() || checkBar();

Even in the best case ;) the transformed code will likely break synchronization rules, i.e.

private volatile int foo;

...
return s.length() + foo;

will transform into

s.length(); 

and will not trigger the half-synchronization on 'foo'.
Comment 2 _ gtzabari 2016-07-14 22:16:07 UTC
If you can't apply the hint safely then the hint shouldn't be provided in the first place :) Either way, the hint should never result in data loss :)
Comment 3 Svata Dedic 2016-07-15 14:11:35 UTC
fixed in jet-main#fe39387af38a(In reply to _ gtzabari from comment #2)
> If you can't apply the hint safely then the hint shouldn't be provided in
> the first place :) Either way, the hint should never result in data loss :)

Well, the fix did exactly what its label said: it removed the [entire] return statement.

New hint fix added in jet-main#fe39387af38a
Comment 4 Quality Engineering 2016-07-19 01:42:45 UTC
Integrated into 'main-silver', will be available in build *201607190002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/fe39387af38a
User: Svata Dedic <sdedic@netbeans.org>
Log: #262290: Return expression can be retained as series of statements