xuzifu666 commented on code in PR #5386:
URL: https://github.com/apache/calcite/pull/5386#discussion_r4481487278


##########
core/src/main/java/org/apache/calcite/util/ReflectUtil.java:
##########
@@ -590,6 +590,37 @@ public static boolean isParameterOptional(Method method, 
int i) {
     return false;
   }
 
+  /** Derives whether the {@code i}th parameter of a method is nullable.
+   *
+   * <p>The algorithm is as follows:
+   * <ul>
+   *   <li>If the parameter has a {@code @Nullable} annotation (from any
+   *       well-known nullness library such as jspecify, Checker Framework,
+   *       or javax.annotation), returns true.</li>
+   *   <li>If the parameter has a {@link Parameter} annotation with
+   *       {@code nullable = false}, returns false.</li>
+   *   <li>Otherwise, returns whether the Java type is not a primitive
+   *       (i.e., the default nullability derived from the type).</li>
+   * </ul>
+   */
+  public static boolean isParameterNullable(Method method, int i) {
+    final Annotation[] annotations = method.getParameterAnnotations()[i];

Review Comment:
   Done. `Parameter.nullable()` is removed entirely and linq4j is back to its 
original state. The public 4-arg `ParameterListBuilder.add()` overload was also 
demoted to private, so no new public API is exposed anywhere.
   
   Nullness is now read from type-use annotations only, specifically jspecify:
   1. ReflectUtil.isParameterNullable reads 
method.getAnnotatedParameterTypes()[i].getAnnotations() (you're right that 
getParameterAnnotations() never sees these TYPE_USE annotations) and matches 
org.jspecify.annotations.Nullable / NonNull by fully qualified name, so no 
dependency on jspecify and no simple-name matching of arbitrary Nullable 
annotations.
   2.  An unannotated reference type is non-null only inside a null-marked 
scope: the innermost @NullMarked / @NullUnmarked on the method, an enclosing 
class, the package, or the module decides. Elsewhere it keeps the historical 
nullable default, so UDFs without jspecify annotations keep their types.
   3. Primitives are never nullable (this also fixes the bug you spotted at 
line 617, where @Parameter int n became a nullable Integer; there is now a test 
asserting a primitive parameter with @Parameter stays NOT NULL).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to