Skip to content

Failing constraint printed twice for type.arguments.not.inferred error #7134

@msridhar

Description

@msridhar

Example:

import java.util.*;
import org.checkerframework.checker.nullness.qual.*;
class Test {
  public static <T extends @Nullable Object> T firstOrDefault(List<T> list, T defaultValue) {
    return list.isEmpty() ? defaultValue : list.get(0);
  }
  public static <U extends @Nullable Object> List<U> singletonList(U o) {
    throw new RuntimeException();
  }

  String field = firstOrDefault(singletonList(null), "hello");
}

Nullness Checker output:

$ path/to/checker/bin/javac -processor nullness Test.java
Test.java:13: error: [assignment] incompatible types in assignment.
  String field = firstOrDefault(singletonList(null), "hello");
                               ^
  found   : @Initialized @Nullable String
  required: @Initialized @NonNull String
Test.java:13: error: [type.arguments.not.inferred] Could not infer type arguments for Test.firstOrDefault
  String field = firstOrDefault(singletonList(null), "hello");
                               ^
  unsatisfiable constraint: @org.checkerframework.checker.nullness.qual.Nullable <: @org.checkerframework.checker.nullness.qual.NonNull
  @org.checkerframework.checker.nullness.qual.Nullable <: @org.checkerframework.checker.nullness.qual.NonNull
2 errors

The unsat constraint @org.checkerframework.checker.nullness.qual.Nullable <: @org.checkerframework.checker.nullness.qual.NonNull is printed twice.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions