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

Implement error-prone for basic analysis #2344

Merged
merged 1 commit into from
May 8, 2021
Merged

Conversation

zml2008
Copy link
Member

@zml2008 zml2008 commented May 2, 2021

error-prone is an AP that runs as part of the Java compile performing some helpful checks.

The tool is fairly lenient, and won't fail the build for things that it isn't super confident are bugs. When run on Sponge, it emitted quite a few warnings, but the errors it emitted appeared to all be legitimate bugs.

This came up almost accidentally when I changed IntelliJ to use error-prone for its own compilation, which ended up affecting the whole workspace. Those checks caught a bad copy & paste in Ticks, plus a variety of other odds & ends across the project.

I've disabled some of the more spammy warnings for now, and fixed the easily fixable -- what's left is:

> Task :compileJava
C:\Users\zml\dev\mc\sponge\Sponge\SpongeAPI\src\main\java\org\spongepowered\api\registry\Registry.java:121: warning: [TypeParameterUnusedInFormals] Declaring a type parameter that is only used in the return type is a misuse of ge
nerics: operations on the type parameter are unchecked, it hides unsafe casts at invocations of the method, and it interacts badly with method overload resolution.
    <V extends T> V value(ResourceKey key);
                    ^
    (see https://errorprone.info/bugpattern/TypeParameterUnusedInFormals)
C:\Users\zml\dev\mc\sponge\Sponge\SpongeAPI\src\main\java\org\spongepowered\api\registry\Registry.java:129: warning: [TypeParameterUnusedInFormals] Declaring a type parameter that is only used in the return type is a misuse of ge
nerics: operations on the type parameter are unchecked, it hides unsafe casts at invocations of the method, and it interacts badly with method overload resolution.
    default <V extends T> V value(final RegistryKey<T> key) {
                            ^
    (see https://errorprone.info/bugpattern/TypeParameterUnusedInFormals)
C:\Users\zml\dev\mc\sponge\Sponge\SpongeAPI\src\main\java\org\spongepowered\api\world\volume\stream\StreamOptions.java:175: warning: [EmptyBlockTag] A block tag (@param, @return, @throws, @deprecated) has an empty description. Bl
ock tags without descriptions don't add much value for future readers of the code; consider removing the tag entirely or adding a description.
     * @return
       ^
    (see https://google.github.io/styleguide/javaguide.html#s7.1.3-javadoc-block-tags)
  Did you mean '*'?
C:\Users\zml\dev\mc\sponge\Sponge\SpongeAPI\src\main\java\org\spongepowered\api\world\volume\stream\VolumeElement.java:105: warning: [EmptyBlockTag] A block tag (@param, @return, @throws, @deprecated) has an empty description. Bl
ock tags without descriptions don't add much value for future readers of the code; consider removing the tag entirely or adding a description.
     * @return
       ^
    (see https://google.github.io/styleguide/javaguide.html#s7.1.3-javadoc-block-tags)
  Did you mean '*'?
C:\Users\zml\dev\mc\sponge\Sponge\SpongeAPI\src\main\java\org\spongepowered\api\world\volume\stream\VolumePositionTranslator.java:33: warning: [EmptyBlockTag] A block tag (@param, @return, @throws, @deprecated) has an empty descr
iption. Block tags without descriptions don't add much value for future readers of the code; consider removing the tag entirely or adding a description.
 * @param <V>
   ^
    (see https://google.github.io/styleguide/javaguide.html#s7.1.3-javadoc-block-tags)
  Did you mean '*'?
C:\Users\zml\dev\mc\sponge\Sponge\SpongeAPI\src\main\java\org\spongepowered\api\world\volume\stream\VolumePositionTranslator.java:34: warning: [EmptyBlockTag] A block tag (@param, @return, @throws, @deprecated) has an empty descr
iption. Block tags without descriptions don't add much value for future readers of the code; consider removing the tag entirely or adding a description.
 * @param <T>
   ^
    (see https://google.github.io/styleguide/javaguide.html#s7.1.3-javadoc-block-tags)
  Did you mean '*'?
C:\Users\zml\dev\mc\sponge\Sponge\SpongeAPI\src\main\java\org\spongepowered\api\data\DataManipulator.java:500: warning: [CatchAndPrintStackTrace] Logging or rethrowing exceptions should usually be preferred to catching and callin
g printStackTrace
                    e.printStackTrace();
                    ^
    (see https://errorprone.info/bugpattern/CatchAndPrintStackTrace)
C:\Users\zml\dev\mc\sponge\Sponge\SpongeAPI\src\main\java\org\spongepowered\api\data\DataManipulator.java:522: warning: [CatchAndPrintStackTrace] Logging or rethrowing exceptions should usually be preferred to catching and callin
g printStackTrace
                    e.printStackTrace();
                    ^
    (see https://errorprone.info/bugpattern/CatchAndPrintStackTrace)
C:\Users\zml\dev\mc\sponge\Sponge\SpongeAPI\src\main\java\org\spongepowered\api\data\DataAlreadyRegisteredException.java:32: warning: [UnusedVariable] The field 'owningRegistration' is never read.
    private final DataRegistration owningRegistration;
                                   ^
    (see https://errorprone.info/bugpattern/UnusedVariable)
  Did you mean to remove this line?
C:\Users\zml\dev\mc\sponge\Sponge\SpongeAPI\src\main\java\org\spongepowered\api\data\DataAlreadyRegisteredException.java:31: warning: [UnusedVariable] The field 'registeredKey' is never read.
    private final Key<?> registeredKey;
                         ^
    (see https://errorprone.info/bugpattern/UnusedVariable)
  Did you mean to remove this line?
C:\Users\zml\dev\mc\sponge\Sponge\SpongeAPI\src\main\java\org\spongepowered\api\util\Coerce.java:767: warning: [MixedMutabilityReturnType] This method returns both mutable and immutable collections or maps from different paths. T
his may be confusing for users of the method.
    private static List<?> parseStringToList(String string) {
                           ^
    (see https://errorprone.info/bugpattern/MixedMutabilityReturnType)
  Did you mean 'private static ImmutableList<?> parseStringToList(String string) {' or 'private static ImmutableList<?> parseStringToList(String string) {'?
11 warnings

@zml2008 zml2008 added type: bug Something isn't working type: enhancement api: 8 (u) version: 1.16 (unsupported since Oct 17th 2023) labels May 2, 2021
@zml2008 zml2008 added this to the Revision 8.0 milestone May 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: 8 (u) version: 1.16 (unsupported since Oct 17th 2023) type: bug Something isn't working type: enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants