-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Add checkerframework and errorprone #2941
base: master
Are you sure you want to change the base?
Conversation
@vlsi Any feedback about the 2 tools and how I added them in the build (even if I was inspired by what you did on pg-driver)? @krmahadevan WDYT? They highlight a lot of minor issues but some potential problems too. |
@juherr - This is definitely a good addition. I am yet to explore both these tools. I have already seen error prone being used by jhipster when it scaffolds a new project based on my inputs. Couple of questions:
|
Thanks.
As I understand, yes. It provides extra data in bytecode thanks to the annotations.
To be honest, I hoped there were a bit less. That's why I sent the draft before fixing them all. |
"nullability" is not trivial, so it might take some time to properly annotate and identify nullable types. |
plugins.withId("org.checkerframework") { | ||
configure<CheckerFrameworkExtension> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plugins { id("org.checkerframework") }
adds checkerframework
plugin, so plugins.withId(..)
is not needed here.
Something like checkerframework {...}
should do.
@@ -1750,7 +1765,8 @@ public static void assertEquals(Iterable<?> actual, Iterable<?> expected, String | |||
* @param expected the expected value | |||
* @param message the assertion error message | |||
*/ | |||
public static void assertEquals(Object[] actual, Object[] expected, String message) { | |||
public static void assertEquals( | |||
@Nullable Object[] actual, @Nullable Object[] expected, @Nullable String message) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it should be @Nullable Object @Nullable [] actual
: nullable array of nullable elements
@@ -17,7 +19,7 @@ public interface IObjectFactory2 extends ITestObjectFactory { | |||
* @return - The newly created object. | |||
*/ | |||
@Deprecated | |||
default Object newInstance(Class<?> cls) { | |||
default Object newInstance(@NonNull Class<?> cls) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to use package-level "default not null" annotation rather than @NotNull
: https://github.com/pgjdbc/pgjdbc/blob/aff581fe806f1c1cdc8bcd9e5a981e37691b44b5/pgjdbc/src/main/java/org/postgresql/package-info.java#L6-L8
See explanation in https://checkerframework.org/manual/#climb-to-top
In my experience, checkerframework nullability verification takes time, so I tend to activate it only when See https://github.com/apache/jmeter/blob/c94db9741f0547235f9a67b1ece40389add6b742/build-logic/build-parameters/build.gradle.kts#L77 , and https://github.com/apache/jmeter/blob/c94db9741f0547235f9a67b1ece40389add6b742/build-logic/verification/src/main/kotlin/build-logic.style.gradle.kts#L42-L43 (conditional activation of |
Thanks for the feedbacks @vlsi ❤️ |
Updated according to reviews. All issues are not fixed yet. Still 2 gradle issues: not succeeding in using the parameters plugin + not finding the way to merge package-info |
@@ -124,7 +126,7 @@ public static void fail() { | |||
* @param expected the expected value | |||
* @param message the assertion error message | |||
*/ | |||
public static void assertEquals(Object actual, Object expected, String message) { | |||
public static void assertEquals(Object actual, Object expected, @Nullable String message) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public static void assertEquals(Object actual, Object expected, @Nullable String message) { | |
public static void assertEquals(@Nullable Object actual, @Nullable Object expected, @Nullable String message) { |
@@ -761,7 +769,7 @@ public static void assertEquals(double actual, Double expected, String message) | |||
* @param expected the expected value | |||
* @param message the assertion error message | |||
*/ | |||
public static void assertEquals(Double actual, Double expected, String message) { | |||
public static void assertEquals(Double actual, Double expected, @Nullable String message) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public static void assertEquals(Double actual, Double expected, @Nullable String message) { | |
public static void assertEquals(@Nullable Double actual, @Nullable Double expected, @Nullable String message) { |
@@ -900,7 +909,7 @@ public static void assertEquals(float actual, Float expected, String message) { | |||
* @param expected the expected value | |||
* @param message the assertion error message | |||
*/ | |||
public static void assertEquals(Float actual, Float expected, String message) { | |||
public static void assertEquals(Float actual, Float expected, @Nullable String message) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public static void assertEquals(Float actual, Float expected, @Nullable String message) { | |
public static void assertEquals(@Nullable Float actual, @Nullable Float expected, @Nullable String message) { |
@@ -1653,7 +1674,7 @@ public static void assertEquals(Collection<?> actual, Collection<?> expected, St | |||
* @param actual the actual value | |||
* @param expected the expected value | |||
*/ | |||
public static void assertEquals(Iterator<?> actual, Iterator<?> expected) { | |||
public static void assertEquals(@Nullable Iterator<?> actual, @Nullable Iterator<?> expected) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public static void assertEquals(@Nullable Iterator<?> actual, @Nullable Iterator<?> expected) { | |
public static void assertEquals(@Nullable Iterator<@Nullable ?> actual, @Nullable Iterator<@Nullable ?> expected) { |
*/ | ||
static boolean wasFailureDueToTimeout(ITestResult result) { | ||
Throwable cause = result.getThrowable(); | ||
@Nullable Throwable cause = result.getThrowable(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically speaking, @Nullable
should be automatically inferred for local variables, so this could probably be omitted
@Nullable Throwable cause = result.getThrowable(); | |
Throwable cause = result.getThrowable(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose you're right.
It means I should not use TypeUseLocation.ALL
in @DefaultQualifier(value = NonNull.class, locations = TypeUseLocation.ALL)
Any other option I should exclude? https://checkerframework.org/api/org/checkerframework/framework/qual/TypeUseLocation.html
@@ -52,7 +53,7 @@ public static void addClassLoader(final ClassLoader loader) { | |||
|
|||
static List<ClassLoader> appendContextualClassLoaders(List<ClassLoader> currentLoaders) { | |||
List<ClassLoader> allClassLoaders = Lists.newArrayList(); | |||
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); | |||
@Nullable ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Nullable ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); | |
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); |
?
} else { | ||
m.addAll(extractedMethod.getValue()); | ||
} | ||
@Nullable Class<?> parent = clazz.getSuperclass(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Nullable Class<?> parent = clazz.getSuperclass(); | |
Class<?> parent = clazz.getSuperclass(); |
private boolean m_enabled = true; | ||
|
||
public ConstructorOrMethod(Method m) { | ||
m_method = m; | ||
m_constructor = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default value is null
anyway, so does it make sense to assign it with null?
I would suggest merging |
@vlsi Thanks for the review. I think your suggestion is a good strategy and I will make another PR with errorprone only. Any idea why I'm not able to use build-parameters? The generated plugin is not found here https://github.com/testng-team/testng/pull/2941/files#diff-5bb00f6e0b0be0ec62ea3824c3888e27921683447cea9fb16bdd9f859f7881acR5 |
Try checkerframework and errorprone