Bug 14588 - NullPointerException in Util.equalArraysOrNull
Summary: NullPointerException in Util.equalArraysOrNull
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P3 minor (vote)
Target Milestone: 2.0 M6   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-04-25 07:23 EDT by Ulrich Kawald CLA
Modified: 2002-05-02 06:57 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ulrich Kawald CLA 2002-04-25 07:23:37 EDT
Method equalArraysOrNull in org.eclipse.jdt.internal.core.Util does not handle 
the case of a null element in either array passed as parameters, which may 
cause a NullPointerException.

We found this bug when using method org.eclipse.jdt.core.Flags.isPublic(), 
which seems to use a HashMap internally. The get() method calls equals() which 
eventually lead to the NullPointerException above. Why one of the elements was 
null we can't explain :-)
Comment 1 Jerome Lanneluc CLA 2002-04-25 11:53:32 EDT
Which build are you using? In build 20020423, Flags.isPublic(int) doesn't use a 
HashMap.
Comment 2 Ulrich Kawald CLA 2002-04-26 02:05:45 EDT
I'm sorry, but I missed a nested method call, the exception really occurred
in a call to org.eclipse.jdt.internal.core.SourceMethod.getFlags() (see the
following stack trace)


org.eclipse.jdt.internal.core.Util.equalArraysOrNull(java.lang.Object[],
java.lang.Object[]) line: 262
org.eclipse.jdt.internal.core.SourceMethod.equals(java.lang.Object) line: 41
java.util.HashMap.get(java.lang.Object) line: 269 [local variables
unavailable]
org.eclipse.jdt.internal.core.JavaModelManager.getInfo(org.eclipse.jdt.core.
IJavaElement) line: 612
org.eclipse.jdt.internal.core.SourceMethod(org.eclipse.jdt.internal.core.Jav
aElement).getElementInfo() line: 274
org.eclipse.jdt.internal.core.SourceMethod(org.eclipse.jdt.internal.core.Mem
ber).getFlags() line: 83
Comment 3 Jerome Lanneluc CLA 2002-04-26 09:25:50 EDT
If you can find a test case where the method is created with a null parameter 
type, I would be very interested in knowing about it.

Otherwise, I added a protection in Util.equalArraysOrNull(Object[], Object[]).
Comment 4 Ulrich Kawald CLA 2002-05-02 06:43:53 EDT
The exception occurred when I accidentally created a non-existing method-object:

IType type;
IJavaElement je = getJavaProject().findElement(new Path(path));
if (je != null) {
  if (je.getElementType() == IJavaElement.COMPILATION_UNIT) {
	type = (IType) ((ICompilationUnit) je).getTypes()[0];
  }
}
IMethod method = type.getMethod(methodName, new String[]{(String) getParams()});
// getParams() did return null
int flags = method.getFlags(); // NullPointerException
Comment 5 Jerome Lanneluc CLA 2002-05-02 06:57:26 EDT
Thanks for the info. I was afraid the method element had been created by the 
jdt/core. null is not specified as being a valid value for one of the parameter 
types in IMethod.getMethod(String, String[]). Thus the previous behavior would 
be expected. However, we now protect ourselfves against such a scenario. 
method.getFlags() will now throw a 'not present' exception.