-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix error-prone mathcing literal null as a subtype. (#1020)
Fix error-prone mathcing literal null as a subtype. The most common issue this fixes is failures on `SafeArg.of("name", null)` assuming that the null literal value parameter may be a throwable.
- Loading branch information
1 parent
e208633
commit e877003
Showing
13 changed files
with
111 additions
and
49 deletions.
There are no files selected for viewing
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
53 changes: 53 additions & 0 deletions
53
baseline-error-prone/src/main/java/com/palantir/baseline/errorprone/MoreMatchers.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,53 @@ | ||
/* | ||
* (c) Copyright 2018 Palantir Technologies Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.palantir.baseline.errorprone; | ||
|
||
import com.google.errorprone.matchers.Matcher; | ||
import com.google.errorprone.matchers.Matchers; | ||
import com.sun.source.tree.Tree; | ||
|
||
/** Additional {@link Matcher} factory methods shared by baseline checks. */ | ||
final class MoreMatchers { | ||
|
||
/** | ||
* Delegates to {@link Matchers#isSubtypeOf(Class)}, but adds a defensive check against null literals | ||
* to work around error-prone#1397. | ||
* | ||
* @see Matchers#isSubtypeOf(Class) | ||
* @see <a href="https://github.com/google/error-prone/issues/1397">error-prone#1397</a> | ||
*/ | ||
static <T extends Tree> Matcher<T> isSubtypeOf(Class<?> baseType) { | ||
return Matchers.allOf( | ||
Matchers.isSubtypeOf(baseType), | ||
Matchers.not(Matchers.kindIs(Tree.Kind.NULL_LITERAL))); | ||
} | ||
|
||
/** | ||
* Delegates to {@link Matchers#isSubtypeOf(String)}, but adds a defensive check against null literals | ||
* to work around error-prone#1397. | ||
* | ||
* @see Matchers#isSubtypeOf(String) | ||
* @see <a href="https://github.com/google/error-prone/issues/1397">error-prone#1397</a> | ||
*/ | ||
static <T extends Tree> Matcher<T> isSubtypeOf(String baseTypeString) { | ||
return Matchers.allOf( | ||
Matchers.isSubtypeOf(baseTypeString), | ||
Matchers.not(Matchers.kindIs(Tree.Kind.NULL_LITERAL))); | ||
} | ||
|
||
private MoreMatchers() {} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
type: fix | ||
fix: | ||
description: |- | ||
Fix error-prone mathcing literal null as a subtype. | ||
The most common issue this fixes is failures on `SafeArg.of("name", null)` | ||
assuming that the null literal value parameter may be a throwable. | ||
links: | ||
- https://github.com/palantir/gradle-baseline/pull/1020 |