checker-framework icon indicating copy to clipboard operation
checker-framework copied to clipboard

Error recognizing Class.isInstance filters out null

Open jpschewe opened this issue 1 year ago • 5 comments

Checker version 3.52.0. Java version: 21.0.8

To reproduce:

  1. mkdir -p net/mtu/eggplant/checker/
  2. cd net/mtu/eggplant/checker/ tar -xzf isinstance_null.tar.gz
  3. 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

jpschewe avatar Nov 07 '25 21:11 jpschewe

Alternative to test

  1. git clone https://github.com/jpschewe/checker-bugs.git
  2. git checkout isinstance-null
  3. ./gradlew classes

jpschewe avatar Nov 07 '25 21:11 jpschewe

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 {}
}

Gaoyan1999 avatar Jan 15 '26 13:01 Gaoyan1999

Has there been any update on this? I see someone was looking into it. Happy to take a look if it's still available.

bitflicker64 avatar Jan 27 '26 20:01 bitflicker64

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.

Gaoyan1999 avatar Jan 28 '26 02:01 Gaoyan1999

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 !!

bitflicker64 avatar Jan 28 '26 02:01 bitflicker64