-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix JDK compatibility issue in LombokHandler and introduce AstHelpers…
…Backports (#795) Fixes #794. Since the JDK interface change was made for JDK 17, I think even if NullAway was built on and targeted JDK 11, we would still have this problem. I added some hacky unit test coverage for this code so we'd have a way to test for regressions in the future. (The new unit test fails the `:nullaway:testJdk8` task without this change.) We missed this problem earlier since we suppressed a warning from `AstHelpersSuggestions`. Even though we cannot accept some of the suggestions from that check (since we may not require a recent enough version of Error Prone), the issues it flags can be serious. So, this PR removes all other suppressions of that checker and fixes the warnings. We introduce an `AstHelpersBackports` class to contain any backported logic from `AstHelpers` to enable the fixes.
- Loading branch information
Showing
10 changed files
with
84 additions
and
45 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
nullaway/src/main/java/com/uber/nullaway/ASTHelpersBackports.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.uber.nullaway; | ||
|
||
import com.sun.tools.javac.code.Symbol; | ||
import java.util.List; | ||
|
||
/** | ||
* Methods backported from {@link com.google.errorprone.util.ASTHelpers} since we do not yet require | ||
* a recent-enough Error Prone version. The methods should be removed once we bump our minimum Error | ||
* Prone version accordingly. | ||
*/ | ||
public class ASTHelpersBackports { | ||
|
||
private ASTHelpersBackports() {} | ||
|
||
/** | ||
* Returns true if the symbol is static. Returns {@code false} for module symbols. Remove once we | ||
* require Error Prone 2.16.0 or higher. | ||
*/ | ||
@SuppressWarnings("ASTHelpersSuggestions") | ||
public static boolean isStatic(Symbol symbol) { | ||
if (symbol.getKind().name().equals("MODULE")) { | ||
return false; | ||
} | ||
return symbol.isStatic(); | ||
} | ||
|
||
/** | ||
* A wrapper for {@link Symbol#getEnclosedElements} to avoid binary compatibility issues for | ||
* covariant overrides in subtypes of {@link Symbol}. | ||
* | ||
* <p>Same as this ASTHelpers method in Error Prone: | ||
* https://github.com/google/error-prone/blame/a1318e4b0da4347dff7508108835d77c470a7198/check_api/src/main/java/com/google/errorprone/util/ASTHelpers.java#L1148 | ||
* TODO: delete this method and switch to ASTHelpers once we can require Error Prone 2.20.0 | ||
*/ | ||
public static List<Symbol> getEnclosedElements(Symbol symbol) { | ||
return symbol.getEnclosedElements(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters