Skip to content

Type argument inference crashed #7683

Description

@cushon
import java.util.List;
import java.util.stream.Collector;

public class CrashRepro {
  static <E> Collector<E, ?, List<E>> toList() {
    throw new UnsupportedOperationException();
  }

  Object convert(Object value) {
    if (value instanceof List) {
      return ((List) value).stream().map(item -> convert(item)).collect(toList());
    }

    return value;
  }
}
$ ./checker-framework-4.0.0/checker/bin/javac -processor nullness CrashRepro.java |& head -n 30
CrashRepro.java:11: error: [return] incompatible types in return.
      return ((List) value).stream().map(item -> convert(item)).collect(toList());
                                                                       ^
  type of expression: @Initialized @Nullable Object
  method return type: @Initialized @NonNull Object
CrashRepro.java:11: error: [type.arguments.not.inferred] Could not infer type arguments for Stream.collect
      return ((List) value).stream().map(item -> convert(item)).collect(toList());
                                                                       ^
  unsatisfiable constraint: @Initialized @Nullable Object -> @Initialized @NonNull Object
  From: Constraint between method call type and target type for method call:((List)value).stream().map((item)->convert(item)).collect(toList())
CrashRepro.java:11: error: [type.argument.inference.crashed] Type argument inference crashed for CrashRepro.toList
      return ((List) value).stream().map(item -> convert(item)).collect(toList());
                                                                              ^
  error: An exception occurred: Cannot invoke "java.util.Map.keySet()" because "map" is null
Note: CrashRepro.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
3 errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions