summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPekka Enberg <penberg@kernel.org>2011-01-21 19:59:14 +0000
committerPekka Enberg <penberg@kernel.org>2011-01-21 19:59:14 +0000
commit619328402e3b911276ec054ea5654b6e0b620934 (patch)
tree475882187082bd58997558c746ee63b253f248e3
parent75fa6e7bf636b038835dbb63c133c7e1b79cd048 (diff)
downloadclasspath-619328402e3b911276ec054ea5654b6e0b620934.tar.gz
Fix java.lang.Class field and method API for null names
2011-01-21 Pekka Enberg <penberg@kernel.org> * java/lang/Class.java: (getDeclaredField): Throw NullPointerException instead of NoSuchFieldException if name is null. (getField): Likewise. (getDeclaredMethod): Throw NullPointerException instead of NoSuchMethodException if name is null. (getMethod): Likewise.
-rw-r--r--ChangeLog10
-rw-r--r--java/lang/Class.java12
2 files changed, 22 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 8d7f07322..4d0bf6dbd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2011-01-21 Pekka Enberg <penberg@kernel.org>
+
+ * java/lang/Class.java:
+ (getDeclaredField): Throw NullPointerException instead of
+ NoSuchFieldException if name is null.
+ (getField): Likewise.
+ (getDeclaredMethod): Throw NullPointerException instead of
+ NoSuchMethodException if name is null.
+ (getMethod): Likewise.
+
2010-12-25 Andrew John Hughes <ahughes@redhat.com>
PR classpath/42390
diff --git a/java/lang/Class.java b/java/lang/Class.java
index 1caee0147..af0a0a2a0 100644
--- a/java/lang/Class.java
+++ b/java/lang/Class.java
@@ -440,11 +440,14 @@ public final class Class<T>
* @return the field
* @throws NoSuchFieldException if the field does not exist
* @throws SecurityException if the security check fails
+ * @throws NullPointerException if <code>fieldName</code> is null
* @see #getDeclaredFields()
* @since 1.1
*/
public Field getDeclaredField(String name) throws NoSuchFieldException
{
+ if (name == null)
+ throw new NullPointerException();
memberAccessCheck(Member.DECLARED);
Field[] fields = getDeclaredFields(false);
for (int i = 0; i < fields.length; i++)
@@ -496,12 +499,15 @@ public final class Class<T>
* @return the method
* @throws NoSuchMethodException if the method does not exist
* @throws SecurityException if the security check fails
+ * @throws NullPointerException if <code>methodName</code> is null
* @see #getDeclaredMethods()
* @since 1.1
*/
public Method getDeclaredMethod(String methodName, Class<?>... types)
throws NoSuchMethodException
{
+ if (methodName == null)
+ throw new NullPointerException();
memberAccessCheck(Member.DECLARED);
Method match = matchMethod(getDeclaredMethods(false), methodName, types);
if (match == null)
@@ -560,12 +566,15 @@ public final class Class<T>
* @return the field
* @throws NoSuchFieldException if the field does not exist
* @throws SecurityException if the security check fails
+ * @throws NullPointerException if <code>fieldName</code> is null
* @see #getFields()
* @since 1.1
*/
public Field getField(String fieldName)
throws NoSuchFieldException
{
+ if (fieldName == null)
+ throw new NullPointerException();
memberAccessCheck(Member.PUBLIC);
Field field = internalGetField(fieldName);
if (field == null)
@@ -700,12 +709,15 @@ public final class Class<T>
* @return the method
* @throws NoSuchMethodException if the method does not exist
* @throws SecurityException if the security check fails
+ * @throws NullPointerException if <code>methodName</code> is null
* @see #getMethods()
* @since 1.1
*/
public Method getMethod(String methodName, Class<?>... types)
throws NoSuchMethodException
{
+ if (methodName == null)
+ throw new NullPointerException();
memberAccessCheck(Member.PUBLIC);
Method method = internalGetMethod(methodName, types);
if (method == null)