Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.16.0 introduces compilation failures around use of getClass() #5431

Closed
kennknowles opened this issue Dec 2, 2022 · 6 comments
Closed

3.16.0 introduces compilation failures around use of getClass() #5431

kennknowles opened this issue Dec 2, 2022 · 6 comments

Comments

@kennknowles
Copy link
Contributor

(I wrote to checkerframework-discuss mailing list but also submitting here for exposure)

TL;DR: It seems that most or all uses of getClass() produce [super @KeyForBottom Void] and the uses in the code expect [super @UnknownKeyFor NullType] starting with checkerframework 3.16.0. Is there some specific change in 3.16.0 that introduces this that I can learn about? Does anyone know how to work around it?

Details:

I am trying to upgrade the checkerframework version used by Apache Beam. When I reach 3.16.0 I hit a new issue I do not yet understand how to fix. The issue persists through 3.27.0. There are checker framework crashes in 3.16.0 and 3.17.0 that are not relevant, so I will submit my question with 3.18.0.

It seems most of the errors are roughly similar. Here is one (note that the method name is "TypeDescriptors.of" so it reads a little funny):

TypeDescriptors.java:354: error: [type.argument] incompatible type argument for type parameter T extends Object of of.
         (TypeDescriptor<T>) TypeDescriptor.of(instance.getClass()), supertype, extractor);
                                          ^
  found   : capture#464[ extends @UnknownKeyFor Object super @KeyForBottom Void]
  required: [extends @UnknownKeyFor Object super @UnknownKeyFor NullType]

The code in question:

public static <T, V> TypeDescriptor<V> extractFromTypeParameters(
    @NonNull T instance, Class<? super T> supertype, TypeVariableExtractor<T, V> extractor) {
  return extractFromTypeParameters(
      (TypeDescriptor<T>) TypeDescriptor.of(instance.getClass()), supertype, extractor);
}

There are quite a few other similar, typically simple, uses.


Commands to reproduce:

git clone https://github.com/apache/beam.git --branch 7c412bd19b36c598fd9abb934631c340827d8778
cd beam
./gradlew compileJava

Expectation: compile success as it succeeds with 3.15.0 and below.
Actual result: compile failure as above.

@smillst
Copy link
Member

smillst commented Dec 2, 2022

The defaulting annotations of lower bounds for the KeyFor Checker changed. The manual explains the defaulting, why you are seeing errors, and how to fix them. Let us know if we need to clarify anything.

@kennknowles
Copy link
Contributor Author

Thank you! Giving it a try...

@kennknowles
Copy link
Contributor Author

Follow-up question: what is the danger of the unsoundness introduced by suppressing keyfor warnings while keeping nullness warnings? Will all Map.get calls be treated as Nullable hence there is no unsoundness introduced?

@kennknowles
Copy link
Contributor Author

I am asking this because the annotations in Beam for this case are getting esoteric enough that I worry about people pushing back on our use of checker.

@smillst
Copy link
Member

smillst commented Dec 7, 2022

Follow-up question: what is the danger of the unsoundness introduced by suppressing keyfor warnings while keeping nullness warnings? Will all Map.get calls be treated as Nullable hence there is no unsoundness introduced?

If your code has no @KeyFor annotations, then I don't think suppressing the keyfor warnings will introduce any unsoundness.

@kennknowles
Copy link
Contributor Author

Awesome, that works perfectly for us at this time.

@mernst mernst closed this as completed Jan 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants