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

Bug 350768

Summary: [quick fix] Invalid proposal to insert try/catch for unhandled exception whose type is a type parameter
Product: [Eclipse Project] JDT Reporter: Ayushman Jain <amj87.iitr>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: minor    
Priority: P3 CC: deepakazad, manju656, markus.kell.r
Version: 3.7   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: stalebug

Description Ayushman Jain CLA 2011-06-30 02:23:51 EDT
Build id:  I20110613-1736

public class X<T extends Exception> {
    public <Z extends Exception> void  foo(boolean bool, Z z){
        try {
            if (bool) 
                throw z;   // Quick fix here
            else
                throw new NullPointerException();
        } catch (RuntimeException e) {
        } 
    }
}

The quick fix offers 2 invalid proposals - "surround with try/catch" and "add catch clause to surrounding try". Both of these will cause a catch (Z z) to be added, which is invalid since type parameters can't be caught.
Comment 1 Deepak Azad CLA 2012-02-01 23:48:22 EST
(In reply to comment #0)
> The quick fix offers 2 invalid proposals - "surround with try/catch" and "add
> catch clause to surrounding try". Both of these will cause a catch (Z z) to be
> added, which is invalid since type parameters can't be caught.

I am thinking of offering the quick fixes with 'Exception' instead of 'Z'. Just to be clear, I am not using the type bounds of the type parameter here i.e. I would use 'Exception' even when the type variable is defined as <Z extends IOException>. 

Any objections ?
Comment 2 Martin Mathew CLA 2014-02-24 23:55:58 EST
Spawned from bug 424616 comment 0:

public class AddThrows {
  interface Getter2<T, E extends Exception> { T get() throws E; }
  
  public static Long main2(Getter2<Long, ?> getter) {
    Long value = getter == null ? 0l : 1l;
    /* uncomment next line, then press CTRL-1 and
     * select either "add throws.." or "surround.." quick fix. */
    //value = getter.get();
    return value;
  }
}

Both the quick fixes gives ? as the type in the catch block and throws clause which needs to be handled.
Comment 3 Markus Keller CLA 2014-03-13 14:45:57 EDT
(In reply to Manju Mathew from comment #2)
> Spawned from bug 424616 comment 0:

That's a different problem (not about throwing a type variable) and will be solved in that bug.
Comment 4 Eclipse Genie CLA 2020-01-24 19:08:49 EST
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. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. 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.