From cebb6034b3f9041713b4d1b46b6880baf5701907 Mon Sep 17 00:00:00 2001 From: Chris Povirk Date: Mon, 7 Oct 2024 12:24:52 -0400 Subject: [PATCH] Accept a null array of parameter types for more methods. (#98) We already do this for `getMethod`. In fairness, `getMethod` has clear docs about it. These other methods do not. Still, I think that `@Nullable` is justified, as I discussed in https://github.com/jspecify/jdk/issues/96 Fixes https://github.com/jspecify/jdk/issues/96 --- src/java.base/share/classes/java/lang/Class.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/java.base/share/classes/java/lang/Class.java b/src/java.base/share/classes/java/lang/Class.java index 42bf67f0463..7237facb894 100644 --- a/src/java.base/share/classes/java/lang/Class.java +++ b/src/java.base/share/classes/java/lang/Class.java @@ -2518,7 +2518,7 @@ public Method getMethod(String name, Class @Nullable ... parameterTypes) */ @CallerSensitive - public Constructor getConstructor(Class... parameterTypes) + public Constructor getConstructor(Class @Nullable ... parameterTypes) throws NoSuchMethodException, SecurityException { @SuppressWarnings("removal") @@ -2923,7 +2923,7 @@ public Field getDeclaredField(String name) * @since 1.1 */ @CallerSensitive - public Method getDeclaredMethod(String name, Class... parameterTypes) + public Method getDeclaredMethod(String name, Class @Nullable ... parameterTypes) throws NoSuchMethodException, SecurityException { Objects.requireNonNull(name); @SuppressWarnings("removal") @@ -3020,7 +3020,7 @@ Method findMethod(boolean publicOnly, String name, Class... parameterTypes) { * @since 1.1 */ @CallerSensitive - public Constructor getDeclaredConstructor(Class... parameterTypes) + public Constructor getDeclaredConstructor(Class @Nullable ... parameterTypes) throws NoSuchMethodException, SecurityException { @SuppressWarnings("removal")