Error recognizing Class.isInstance filters out null
Checker version 3.52.0. Java version: 21.0.8
To reproduce:
- mkdir -p net/mtu/eggplant/checker/
- cd net/mtu/eggplant/checker/ tar -xzf isinstance_null.tar.gz
- Build this with checker. Result is
/home/jpschewe/projects/checker-bugs/src/main/java/net/mtu/eggplant/checker/isinstance_null/Test.java:21: error: [argument] incompatible argument for parameter goal of Test.findRangeShortDescriptionWithTitle.
.map(g -> findRangeShortDescriptionWithTitle(title, g))//
^
found : @Initialized @PolyNull Goal
required: @Initialized @NonNull Goal
1 error
Alternative to test
- git clone https://github.com/jpschewe/checker-bugs.git
- git checkout isinstance-null
- ./gradlew classes
I reproduced the issue with a minimal code example. Interestingly, when I changed .map(Goal.class::cast) to .map(a -> Goal.class.cast(a)), the project built successfully.
I’ve been trying to fix this over the past few days, but I haven’t been able to resolve it yet. I would really appreciate any insights or guidance. I’m very happy to keep working on this. Thx in advance. :)
// Test case for Issue 7365:
// https://github.com/typetools/checker-framework/issues/7365
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
public class Issue7365 {
private static Optional<String> findRangeShortDescriptionWithTitle(String title, Goal goal) {
return Optional.empty();
}
public static List<AbstractGoal> getAllGoals() {
return new LinkedList<>();
}
private static void trigger(String title) {
getAllGoals().stream()
// .map(a -> Goal.class.cast(a)) // works
.map(Goal.class::cast) // fails
.map(g -> findRangeShortDescriptionWithTitle(title, g));
}
public abstract static class AbstractGoal {}
public static class Goal extends AbstractGoal {}
}
Has there been any update on this? I see someone was looking into it. Happy to take a look if it's still available.
Has there been any update on this? I see someone was looking into it. Happy to take a look if it's still available.
I think no one is on this currently, you can give it a try.
Has there been any update on this? I see someone was looking into it. Happy to take a look if it's still available.
I think no one is on this currently, you can give it a try.
thanks a bunch !!