Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
a1e4bb8
WIP
msridhar Jan 29, 2026
22fb655
test case
msridhar Feb 6, 2026
e86b344
tweak test
msridhar Feb 6, 2026
81f952c
better tests
msridhar Feb 6, 2026
03ce931
WIP
msridhar Feb 6, 2026
dfba3e5
docs
msridhar Feb 6, 2026
fdf01ee
WIP
msridhar Feb 6, 2026
4446516
simplify
msridhar Feb 6, 2026
dc3a227
more
msridhar Feb 6, 2026
471701d
simplify
msridhar Feb 6, 2026
aea98ae
simplify
msridhar Feb 6, 2026
0e2df18
reuse helper method
msridhar Feb 6, 2026
e607850
bug fix
msridhar Feb 6, 2026
d1636f7
fix nested constructors
msridhar Feb 7, 2026
c6c1e9a
fix diagnostic message
msridhar Feb 7, 2026
68ad56d
simplify
msridhar Feb 7, 2026
02d32b6
small fix
msridhar Feb 8, 2026
ec32f89
another fix
msridhar Feb 8, 2026
bae860f
Merge branch 'master' into issue-1451
msridhar Feb 8, 2026
e1d8386
Merge branch 'master' into issue-1451
msridhar Feb 14, 2026
89bb268
failing test
msridhar Feb 14, 2026
36ac60c
test fix
msridhar Feb 14, 2026
65fc519
tweaks
msridhar Feb 14, 2026
2454efd
docs
msridhar Feb 15, 2026
df8f89e
add issue links
msridhar Feb 15, 2026
82e633e
remove unnecessary code
msridhar Feb 15, 2026
319f453
more coderabbit comments
msridhar Feb 15, 2026
1374e89
Merge branch 'master' into issue-1451
msridhar Feb 17, 2026
4babffe
test of Void without @Nullable
msridhar Feb 18, 2026
78501f2
extract helper to check for raw types and use for NewClassTrees
msridhar Feb 18, 2026
2c50426
add tracking issue
msridhar Feb 18, 2026
95ee81d
add another link to issue
msridhar Feb 18, 2026
39898d7
tweak comment
msridhar Feb 18, 2026
bfd95f7
get rid of withPathToSubtree
msridhar Feb 19, 2026
d50bf7b
WIP
msridhar Feb 19, 2026
bc76012
fixes
msridhar Feb 19, 2026
2883e5a
add case and TODO for ConditionalExpressionTree
msridhar Feb 19, 2026
e321bbc
Merge branch 'master' into issue-1451
msridhar Feb 21, 2026
dc9d2dc
try throwing
msridhar Feb 21, 2026
829490a
don't throw, but track in an issue
msridhar Feb 21, 2026
caa54dd
add javadoc
msridhar Feb 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs
  • Loading branch information
msridhar committed Feb 6, 2026
commit dfba3e5aa2fd8481b48f8d16146b95ede32653c6
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,7 @@ private void reportInvalidOverridingMethodParamTypeError(
return result;
}
if (tree instanceof NewClassTree newClassTree) {
if (newClassTree.getClassBody() != null
&& newClassTree.getIdentifier() instanceof JCTree idTree
&& TreeInfo.isDiamond(idTree)) {
if (isDiamondAnonymousClass(newClassTree)) {
// Keep existing behavior for diamond anonymous classes, which are not yet fully supported.
return null;
}
Expand Down Expand Up @@ -557,6 +555,10 @@ private void reportInvalidOverridingMethodParamTypeError(
return getDiamondTypeFromParentContext(tree, state, parentPath);
}

/**
* Same as {@link #getDiamondTypeFromContext(NewClassTree, VisitorState)} but starts from the
* current path when that path already refers to an enclosing context.
*/
private @Nullable Type getDiamondTypeFromCurrentPath(NewClassTree tree, VisitorState state) {
TreePath currentPath = state.getPath();
if (currentPath == null) {
Expand All @@ -568,6 +570,10 @@ private void reportInvalidOverridingMethodParamTypeError(
return getDiamondTypeFromParentContext(tree, state, currentPath);
}

/**
* Computes the assignment-context type for an inferred constructor call, given a path to its
* parent context.
*/
private @Nullable Type getDiamondTypeFromParentContext(
NewClassTree tree, VisitorState state, TreePath parentPath) {
Tree parent = parentPath.getLeaf();
Expand Down Expand Up @@ -604,40 +610,41 @@ private void reportInvalidOverridingMethodParamTypeError(
if (methodType == null) {
return null;
}
AtomicReference<@Nullable Type> formalParamTypeRef = new AtomicReference<>();
new InvocationArguments(parentInvocation, methodType.asMethodType())
.forEach(
(arg, pos, formalParamType, unused) -> {
if (ASTHelpers.stripParentheses(arg) == tree) {
formalParamTypeRef.set(formalParamType);
}
});
return formalParamTypeRef.get();
return getFormalParameterTypeForArgument(parentInvocation, methodType.asMethodType(), tree);
}
if (parent instanceof NewClassTree parentConstructorCall) {
Type parentCtorType = ASTHelpers.getType(parentConstructorCall.getIdentifier());
if (parentCtorType == null) {
return getTargetTypeForDiamond(state, parentPath);
}
AtomicReference<@Nullable Type> formalParamTypeRef = new AtomicReference<>();
new InvocationArguments(parentConstructorCall, parentCtorType.asMethodType())
.forEach(
(arg, pos, formalParamType, unused) -> {
if (ASTHelpers.stripParentheses(arg) == tree) {
formalParamTypeRef.set(formalParamType);
}
});
return formalParamTypeRef.get();
return getFormalParameterTypeForArgument(
parentConstructorCall, parentCtorType.asMethodType(), tree);
}
Comment on lines +598 to +611
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search for ASTHelpers.getSymbol usage with NewClassTree in the codebase
rg -n --type=java 'ASTHelpers\.getSymbol\(' nullaway/src/main/java/ | head -50

Repository: uber/NullAway

Length of output: 7770


🏁 Script executed:

#!/bin/bash
# Check the specific file and surrounding context for how getSymbol is used with NewClassTree
# Also look for other NewClassTree getSymbol usages
rg -n --type=java -B2 -A2 'NewClassTree' nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java | grep -A5 -B5 'getSymbol'

Repository: uber/NullAway

Length of output: 39


🏁 Script executed:

#!/bin/bash
# Look at the exact context in the file at lines 598-611 and check for null checks
sed -n '590,620p' nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java

Repository: uber/NullAway

Length of output: 1324


🏁 Script executed:

#!/bin/bash
# Check TypeSubstitutionUtils.memberType implementation to see if it handles null
rg -n --type=java 'public.*memberType' nullaway/src/main/java/com/uber/nullaway/

Repository: uber/NullAway

Length of output: 218


🏁 Script executed:

#!/bin/bash
# Search for TypeSubstitutionUtils.memberType to understand its signature
rg -n --type=java -A10 'static.*memberType' nullaway/src/main/java/com/uber/nullaway/

Repository: uber/NullAway

Length of output: 1493


🏁 Script executed:

#!/bin/bash
# Check if there are other places in the codebase where getSymbol(NewClassTree) is used
# and how they handle potential null
rg -n --type=java -B3 -A3 'NewClassTree' nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java | head -100

Repository: uber/NullAway

Length of output: 4962


🏁 Script executed:

#!/bin/bash
# Check the implementation details and null handling in TypeSubstitutionUtils.memberType
cat -n nullaway/src/main/java/com/uber/nullaway/generics/TypeSubstitutionUtils.java | sed -n '67,77p'

Repository: uber/NullAway

Length of output: 690


🏁 Script executed:

#!/bin/bash
# Look for any defensive null checks after getSymbol(NewClassTree) in the codebase
rg -n --type=java -B2 -A5 'NewClassTree.*=' nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java | grep -A5 'getSymbol'

Repository: uber/NullAway

Length of output: 39


🏁 Script executed:

#!/bin/bash
# Check if there are other instances where getSymbol result from NewClassTree is used
# and whether null checks are applied
rg -n --type=java 'instanceof NewClassTree' nullaway/src/main/java/ -A10 | grep -A10 'getSymbol'

Repository: uber/NullAway

Length of output: 1358


🏁 Script executed:

#!/bin/bash
# Check Error Prone's ASTHelpers documentation or implementation for getSymbol behavior
# First, let's see if there's any documentation in NullAway about this
rg -n --type=java 'getSymbol.*NewClass' nullaway/src/main/java/ -B5 -A10

Repository: uber/NullAway

Length of output: 39


🏁 Script executed:

#!/bin/bash
# Check if there are any null checks or error handling after getSymbol(NewClassTree)
# in the entire codebase
rg -n --type=java 'getSymbol\(' nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java | grep -A2 -B2 '602'

Repository: uber/NullAway

Length of output: 436


🏁 Script executed:

#!/bin/bash
# Look at how getSymbol is typically used after being called
# Check patterns of null checking around line 522 where memberSelectSymbol is retrieved
sed -n '515,530p' nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java

Repository: uber/NullAway

Length of output: 925


🏁 Script executed:

#!/bin/bash
# Let's see the context around line 522 more clearly to confirm null checking pattern
sed -n '520,530p' nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java

Repository: uber/NullAway

Length of output: 639


🏁 Script executed:

#!/bin/bash
# Look at how other similar cases handle getSymbol - check line 502 (assignmentTree)
sed -n '500,510p' nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java

Repository: uber/NullAway

Length of output: 542


🏁 Script executed:

#!/bin/bash
# Check if there are Error Prone docs or other references about getSymbol nullability
# Let's look for any Nullable annotations on the method
rg -n --type=java '@Nullable.*getSymbol|getSymbol.*@Nullable' nullaway/src/

Repository: uber/NullAway

Length of output: 39


🏁 Script executed:

#!/bin/bash
# Final confirmation: check if there are any explicit null-safety guarantees in Error Prone
# by looking at how other overloads of getSymbol are documented/used in NullAway
rg -n --type=java 'ASTHelpers\.getSymbol\(' nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java | head -20

Repository: uber/NullAway

Length of output: 1665


🏁 Script executed:

#!/bin/bash
# Check the broader pattern: do all other Symbol assignments from getSymbol have null checks?
rg -n --type=java 'Symbol.*=.*ASTHelpers\.getSymbol' nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java | wc -l

Repository: uber/NullAway

Length of output: 59


🏁 Script executed:

#!/bin/bash
# Count how many of these have immediate null checks following them
# Let's look at a few more examples to establish the pattern
sed -n '645,680p' nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java

Repository: uber/NullAway

Length of output: 1860


Add null guard for parentCtorSymbol to prevent potential NPE.

ASTHelpers.getSymbol(parentConstructorCall) can return null. The codebase pattern shows null checks for getSymbol() results on MemberSelectTree (line 522) and AssignmentTree (line 502). If parentCtorSymbol is null, TypeSubstitutionUtils.memberType() at line 606 will dereference sym.type and throw an NPE.

🛡️ Proposed null guard
     if (parent instanceof NewClassTree parentConstructorCall) {
       // get the type returned by the parent constructor call
       Type parentClassType = getTreeType(parentConstructorCall, state.withPath(parentPath));
       if (parentClassType != null) {
         Symbol parentCtorSymbol = ASTHelpers.getSymbol(parentConstructorCall);
+        if (parentCtorSymbol == null) {
+          return null;
+        }
         // get the proper type for the constructor, as a member of the type returned by the
         // constructor
         Type parentCtorType =
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java` around
lines 598 - 611, The block handling parent instanceof NewClassTree must
null-check the constructor symbol: after obtaining Symbol parentCtorSymbol =
ASTHelpers.getSymbol(parentConstructorCall) guard if (parentCtorSymbol == null)
and return/fallback (e.g., return null) instead of calling
TypeSubstitutionUtils.memberType with a null symbol; specifically add the null
check before invoking TypeSubstitutionUtils.memberType and only call
getFormalParameterTypeForArgument(parentConstructorCall,
parentCtorType.asMethodType(), tree) when parentCtorSymbol is non-null.

return getTargetTypeForDiamond(state, parentPath);
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

/** Returns the inferred/declared formal parameter type corresponding to {@code argumentTree}. */
private @Nullable Type getFormalParameterTypeForArgument(
Tree invocationTree, Type.MethodType invocationType, Tree argumentTree) {
AtomicReference<@Nullable Type> formalParamTypeRef = new AtomicReference<>();
new InvocationArguments(invocationTree, invocationType)
.forEach(
Comment thread
msridhar marked this conversation as resolved.
(arg, pos, formalParamType, unused) -> {
if (ASTHelpers.stripParentheses(arg) == argumentTree) {
formalParamTypeRef.set(formalParamType);
}
});
return formalParamTypeRef.get();
}
Comment thread
msridhar marked this conversation as resolved.

/** Reads javac's target type for the constructor expression at the given path, if available. */
private static @Nullable Type getTargetTypeForDiamond(VisitorState state, TreePath treePath) {
com.google.errorprone.util.TargetType targetType =
com.google.errorprone.util.TargetType.targetType(state.withPath(treePath));
return targetType == null ? null : targetType.type();
}

/** Finds the path to {@code target} within {@code rootPath}, or null when not found. */
private static @Nullable TreePath findPathToSubtree(@Nullable TreePath rootPath, Tree target) {
if (rootPath == null) {
return null;
Expand All @@ -653,11 +660,16 @@ private void reportInvalidOverridingMethodParamTypeError(
}.scan(rootPath, null);
}

/** Creates a state whose path points to {@code subtree}, when that subtree is reachable. */
private static VisitorState withPathToSubtree(VisitorState state, Tree subtree) {
TreePath subtreePath = findPathToSubtree(state.getPath(), subtree);
return subtreePath == null ? state : state.withPath(subtreePath);
}

/**
* Returns true when javac inferred class type arguments for a constructor call, i.e. there are
* instantiated type arguments at the type level, but no explicit non-diamond source type args.
*/
private static boolean hasInferredClassTypeArguments(NewClassTree newClassTree) {
if (newClassTree.getClassBody() != null) {
// For anonymous classes, javac does not preserve all nullability details for the inferred
Expand All @@ -675,6 +687,12 @@ private static boolean hasInferredClassTypeArguments(NewClassTree newClassTree)
return newClassType != null && !newClassType.getTypeArguments().isEmpty();
}

private static boolean isDiamondAnonymousClass(NewClassTree newClassTree) {
return newClassTree.getClassBody() != null
&& newClassTree.getIdentifier() instanceof JCTree idTree
&& TreeInfo.isDiamond(idTree);
}

/**
* Gets the inferred type of lambda parameter, if the lambda was passed to a generic method and
* its type was inferred previously
Expand Down