Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 285000

Summary: [preferences] Add UI option for unused object allocation problem
Product: [Eclipse Project] JDT Reporter: Olivier Thomann <Olivier_Thomann>
Component: UIAssignee: Markus Keller <markus.kell.r>
Status: VERIFIED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: daniel_megert, deepakazad, markus.kell.r, stephan.herrmann
Version: 3.5   
Target Milestone: 3.6 M5   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on: 236385    
Bug Blocks:    
Attachments:
Description Flags
Proposed fix
none
Same patch with copyright updates
none
Patch 3 none

Description Olivier Thomann CLA 2009-07-29 08:58:42 EDT
Once bug 236385 is fixed, the new option needs to be exposed in the UI.
Comment 1 Markus Keller CLA 2009-07-29 09:37:55 EDT
Maybe also add a quick fix to insert 'throw' (for Throwables) or 'return' (if the type is compatible with the return type of the enclosing method).
Comment 2 Olivier Thomann CLA 2010-01-13 10:20:00 EST
Created attachment 155984 [details]
Proposed fix

This only adds the corresponding option in the preference page under the right category.
Comment 3 Olivier Thomann CLA 2010-01-13 11:41:27 EST
Created attachment 156003 [details]
Same patch with copyright updates
Comment 4 Markus Keller CLA 2010-01-13 14:42:35 EST
Created attachment 156037 [details]
Patch 3

Adds quick fixes and adjusts layout for bug 236385 comment 39.
Comment 5 Markus Keller CLA 2010-01-13 14:43:36 EST
Released Patch 3 to HEAD.
Comment 6 Deepak Azad CLA 2010-01-26 02:34:48 EST
Verified on I20100125-0800
In the following snipped a warning is shown on both object allocations. Quick fix for the exception object includes 'Throw'. This much works as expected.
       public void foo() {
	   if (bar())
	       new IllegalArgumentException("You must not bar!");
	   
	   new String("Unused allocation");
	}

(In reply to comment #1)
> Maybe also add a quick fix to insert 'throw' (for Throwables) or 'return' (if
> the type is compatible with the return type of the enclosing method).
The quick fix also includes return for both objects, even though the return type is not compatible. Is this expected?
Comment 7 Dani Megert CLA 2010-01-26 04:15:35 EST
Verified in I20100125-1800.

>The quick fix also includes return for both objects, even though the return
>type is not compatible. Is this expected?
Filed bug 300778 to track this: the quick fix should either not be offered or it should also replace 'void' with the correct return type.