Community
Participate
Working Groups
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 :-)
Which build are you using? In build 20020423, Flags.isPublic(int) doesn't use a HashMap.
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
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[]).
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
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.