Bug 13906

Summary: Compiler did not detect uncaught exception
Product: [Eclipse Project] JDT Reporter: Philipe Mulet <philippe_mulet>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: RESOLVED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: john, rodrigo
Version: 2.0   
Target Milestone: 2.0 M6   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

Description Philipe Mulet CLA 2002-04-16 12:00:25 EDT
Build 20020412

from Rodrigo Peretti:

The following code (from org.eclipse.core.internal.boot.InternalBootLoader) 
does not compile with javac (I've tried with IBM 1.3, 1.3.1 and Sun's 1.4 
beta). It complains that Throwable should be caught or should be in the throws 
clause. It compiles fine with the JDT compiler. Any ideas?

Rodrigo


/**
 * @see BootLoader
 */
public static Object run(String applicationName/*R1.0 compatibility*/, URL 
pluginPathLocation/*R1.0 compatibility*/, String location, String[] args) 
throws Exception {
	Object result = null;
	applicationR10 = applicationName; // for R1.0 compatibility
	String[] applicationArgs = null;
	try {
		applicationArgs = startup(pluginPathLocation, location, args);
	} catch (Exception e) {
		throw e;
	}
	
	String application = getCurrentPlatformConfiguration
().getApplicationIdentifier();
	IPlatformRunnable runnable = getRunnable(application);
	if (runnable == null)
		throw new IllegalArgumentException("Application not found: " + 
application);
	try {
		result = runnable.run(applicationArgs);
	} catch (Throwable e) {
		e.printStackTrace();
		throw e;
	} finally {
		shutdown();
		return result;
	}
}
Comment 1 Philipe Mulet CLA 2002-04-16 12:01:08 EDT
Simpler test case:

[package p1;

public class X {

	public Object run(Object result) throws Exception {
			
		try {
			System.out.println("aaa");
		} catch (Throwable e) {
			throw e;
		} finally {
			return result;
		}
	}
}]
Comment 2 Philipe Mulet CLA 2002-04-16 12:18:44 EDT
Javac 1.2.2 did also accept this code.
Comment 3 Philipe Mulet CLA 2002-04-18 04:23:34 EDT
The reason why we accept this code is that the offending code actually never 
ends up throwing the Throwable exception. It is intercepted by the finally 
block which instead will return some value.

So in practice, the offending exception doesn't need to be caught.
Comment 4 Philipe Mulet CLA 2002-04-18 07:42:59 EDT
JLS 14.19.2 precisely describe this situation:

14.19.2 Execution of try-catch-finally

A try statement with a finally block is executed by first executing the try 
block. Then there is a choice:
...
If the run-time type of V is not assignable to the parameter of any catch 
clause of the try statement, then the finally block is executed. Then there is 
a choice: 
  ...
  If the finally block completes abruptly for reason S, then the try 
  statement completes abruptly for reason S (and the throw of value V 
  is discarded and forgotten). 
---------
In the original test case, the exception thrown within the catch block isn't 
handled inside this try statement, but the finally block makes it irrelevant.

javac has a bug.
Comment 5 John Dale CLA 2002-04-28 15:15:59 EDT
*** Bug 14818 has been marked as a duplicate of this bug. ***