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

Bug 340634

Summary: [1.7][compiler][multicatch] Compiler accepts type variables as catch parameter type
Product: [Eclipse Project] JDT Reporter: Srikanth Sankaran <srikanth_sankaran>
Component: CoreAssignee: Satyam Kandula <satyam.kandula>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: amj87.iitr, Olivier_Thomann
Version: 3.7   
Target Milestone: 3.7.1   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Proposed patch
none
Patch none

Description Srikanth Sankaran CLA 2011-03-22 06:04:30 EDT
BETA_JAVA7

The following program compiles fine while it should not:

//-----------------------8<------------------------------
public class X<T extends Exception> {
	public void foo(boolean bool) throws Exception {
		try {
			if (bool) 
			    throw new Exception();
			else
			    throw new NullPointerException();
		} catch (T | NullPointerException e) {
		}
	}
}
//-------------------------8<----------------------------

The problem stems from the fact that certain checks that
must be applied on the catch parameter type now get
applied on the lub as opposed to everyone of the constituent
disjucntive type references.

See org.eclipse.jdt.internal.compiler.ast.Argument.resolveForCatch(BlockScope)
and org.eclipse.jdt.internal.compiler.ast.DisjunctiveTypeReference.resolveType(BlockScope, boolean).

Satyam, make sure to carry over all relevant checks
Comment 1 Satyam Kandula CLA 2011-03-28 10:04:06 EDT
Created attachment 192003 [details]
Proposed patch

Pulled in some checks from Argument#resolveForCatch() to DisjunctiveTypeReference#resolveType(). I haven't added the check for void array types as I couldn't find a real usecase.
Comment 2 Satyam Kandula CLA 2011-03-28 10:07:52 EDT
Olivier, 
For this, I pulled some checks in Argument#resolveForCatch() into
DisjunctiveTypeReference#resolveType(). There is one check for void
array type that I didn't understand nor could get a testcase. Do you think we should pull in the check?
Comment 3 Olivier Thomann CLA 2011-03-29 12:08:24 EDT
(In reply to comment #2)
> DisjunctiveTypeReference#resolveType(). There is one check for void
> array type that I didn't understand nor could get a testcase. Do you think we
> should pull in the check?
No, this should actually be removed as this is checked during the resolution of the actual array type reference.
So the code should not be moved to DisjunctiveTypeReference, but should also be removed from Argument#resolveForCatch(..).
Comment 4 Satyam Kandula CLA 2011-03-30 04:16:37 EDT
(In reply to comment #3)
> (In reply to comment #2)
> > DisjunctiveTypeReference#resolveType(). There is one check for void
> > array type that I didn't understand nor could get a testcase. Do you think we
> > should pull in the check?
> No, this should actually be removed as this is checked during the resolution of
> the actual array type reference.
> So the code should not be moved to DisjunctiveTypeReference, but should also be
> removed from Argument#resolveForCatch(..).
Thanks Olivier, I will change resolveForCatch() also.
Comment 5 Satyam Kandula CLA 2011-03-30 04:19:34 EDT
Created attachment 192164 [details]
Patch

Updated patch after removing unused code in Argument.java as per comment 3.
Comment 6 Satyam Kandula CLA 2011-03-30 04:24:43 EDT
Released in BETA_JAVA7 branch
Comment 7 Ayushman Jain CLA 2011-06-30 02:28:12 EDT
Verified using Eclipse Java 7 Support(Beta) feature patch v20110623-0900.