typetools / typetools/checker-framework
Unexpected `type.arguments.not.inferred` error
Open
@smillst is already working on this.
Since Aug 31, 2024.
False Positive (false warning or imprecision)
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 440
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 134
Description
Test case (reduced from other code):
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
class Walker {
List<Foo> b(Path c, ClassProvider classProvider) {
try (Stream<Path> walk = Files.walk(c)) {
return walk.flatMap(
g -> {
return StreamUtils.optionalToStream(classProvider.provide());
})
.collect(Collectors.toList());
} catch (IOException e) {
throw new IllegalArgumentException();
}
}
abstract static class ClassProvider {
abstract Optional<? extends Foo> provide();
}
static class StreamUtils {
static <M> Stream<M> optionalToStream(Optional<M> n) {
return null;
}
}
static class Foo {}
}
If I run it through the Tainting Checker, I get these errors:
$ checker-framework/checker/bin/javac -processor tainting Walker.java
Walker.java:14: error: [return] incompatible types in return.
return StreamUtils.optionalToStream(classProvider.provide());
^
type of expression: @Tainted Stream<@Tainted Foo>
method return type: @Tainted Stream<? extends capture#01 extends @Tainted Foo>
Walker.java:14: error: [type.arguments.not.inferred] Could not infer type arguments for StreamUtils.optionalToStream
return StreamUtils.optionalToStream(classProvider.provide());
^
unsatisfiable constraint: @Tainted Foo <: capture#01 extends @Tainted Foo
2 errors
I get similar errors with the Called Methods Checker / Resource Leak Checker, but not with the Nullness Checker (I do get the expected nullness error in optionalToStream).
Are these errors expected?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.