Bug 24638 - inconsistent use of Jv_FindClass causing too weak error condition
Summary: inconsistent use of Jv_FindClass causing too weak error condition
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libgcj (show other bugs)
Version: 4.0.0
: P3 normal
Target Milestone: 4.2.0
Assignee: Robert Schuster
URL:
Keywords:
Depends on: 24616
Blocks:
  Show dependency treegraph
 
Reported: 2005-11-02 16:34 UTC by Robert Schuster
Modified: 2006-02-01 13:49 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Schuster 2005-11-02 16:34:55 UTC
Jv_FindClass throws a ClassNotFoundException in case the requested class cannot be resolved (regardless of whether the bytecode missing or a further dependency cannot be resolved).

This causes problems because in case of serious bytecode errors (eg. the class of a field is missing) where a NoClassDefFoundError should reach the user code.

I found code in several places in gcj where the caller of Jv_FindClass expected NULL to be returned. This affects Jv_FindClassFromSignature too because it depends on the former function.

Obviously such code will not be executed (unless the Jv_FindClass takes a special codepath where it call Jv_FindClassInCache).

- link.cc: around line 1000, look for:
if (target_class == NULL)
	throw new java::lang::NoClassDefFoundError 
	  (_Jv_NewStringUTF (sym.class_name->chars()));

- verify.cc: around 387, look for
	  data.klass = _Jv_FindClassFromSignature (data.name->chars(), loader);
	  if (data.klass == NULL)
	    throw new java::lang::NoClassDefFoundError(data.name->toString());

I want to hear what the experts have to say about that. My suggestion would be to introduce a special variant of Jv_FindClass which does not throw a ClassNotFoundException (by swallowing it) and then carefully adjusting the code location where the old variant was used.
Comment 1 Robert Schuster 2005-11-16 16:50:27 UTC
By working on PR 24616 I found out that this belongs together.
Comment 2 Robert Schuster 2006-02-01 13:49:10 UTC
The patch for PR 24616 contains variants of the methods I was talking here that do not throw any exception and instead make the caller responsible for throwing the correct exception or error: http://gcc.gnu.org/ml/java-patches/2006-q1/msg00124.html