sevntu-checkstyle / sevntu.checkstyle

Additional Checkstyle checks, that could be added as extension to EclipseCS plugin and maven-checkstyle-plugin, Sonar checkstyle plugin, extension for CheckStyle IDEA plugin.
http://sevntu-checkstyle.github.io/sevntu.checkstyle/
190 stars 147 forks source link

AvoidDefaultSerializableInInnerClassesCheck incompatiblewith Checkstyle 9.1 #875

Closed PhilippWendler closed 2 years ago

PhilippWendler commented 2 years ago

/var/tmp $ javac YOUR_FILE.java

no output

/var/tmp $ cat YOUR_FILE.java

package test;

import java.io.Serializable;

public class Test implements Serializable {

  private static final long serialVersionUID = -344227642091683711L;
}

/var/tmp $ cat config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Checkstyle//DTD Check Configuration 1.3//EN" "https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
  <property name="severity" value="warning"/>
  <module name="TreeWalker">
    <module name="com.github.sevntu.checkstyle.checks.coding.AvoidDefaultSerializableInInnerClassesCheck"/>
  </module>
</module>

For Linux users:

/var/tmp $ java -classpath sevntu-checks-X.XX.X.jar:checkstyle-X.XX-all.jar com.puppycrawl.tools.checkstyle.Main -c config.xml YOUR_FILE.java

Starting audit...
[WARN] src/test/Test.java:5:19: Inner class should not implement default Serializable interface. [AvoidDefaultSerializableInInnerClasses]
Audit done.

This class is not an inner class, thus the warning is wrong. When combining sevntu-checkstyle 1.40.0 with Checkstyle 9.1, this warning is produced for all serializable classes. With Checkstyle 8.45.1 it works as expected.

rnveach commented 2 years ago

The check was broken when we added the new COMPILATION_UNIT in 9.0 . We do have a PR to update the checks, https://github.com/sevntu-checkstyle/sevntu.checkstyle/pull/858 , but it has not been merged yet since sevntu still relies on an outdated checkstyle version.

Until it is fixed, I recommend to stick with the version sevntu uses, which is 8.44. https://github.com/sevntu-checkstyle/sevntu.checkstyle/blob/master/sevntu-checks/pom.xml#L19

PhilippWendler commented 2 years ago

Thanks for the explanation! No hurry.

PhilippWendler commented 2 years ago

Works now with release 1.41.0.