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

Issue #5899: Add InterfaceImpliedModifierCheck #5974

Merged
merged 1 commit into from Jul 6, 2018

Conversation

jodastephen
Copy link
Contributor

This PR implements #5899 with one extra property - violateImpliedPublicNested - which was missing from the discussion. All tests/checks pass locally. The translations are automated. Thanks for your consideration!

@rnveach
Copy link
Member

rnveach commented Jun 27, 2018

CI failures are related to TC Violations (IDEA) and travis violations (Eclipse and spellchecker).
You can find the details of the issues by clicking Details next to the CI. TC allows guest sign-in, so you don't need to sign up.

@@ -654,6 +654,8 @@ private static void fillChecksFromModifierPackage() {
BASE_PACKAGE + ".checks.modifier.ModifierOrderCheck");
NAME_TO_FULL_MODULE_NAME.put("RedundantModifierCheck",
BASE_PACKAGE + ".checks.modifier.RedundantModifierCheck");
NAME_TO_FULL_MODULE_NAME.put("InterfaceMemberImpliedModifierCheck",
BASE_PACKAGE + ".checks.modifier.InterfaceMemberImpliedModifierCheck");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please order the checks alphabetically.

import com.puppycrawl.tools.checkstyle.api.TokenTypes;

/**
* Checks modifiers on interface members, ensuring that certain modifiers are
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


Add your check name to the list and fix all violations the test produce. It will align your Javadoc based on what is supplied in the XDoc.
Let us know if you run into any issues or have questions.

@@ -1,3 +1,4 @@
annotation.order=El modificador de anotación ''{0}'' no precede a los modificadores normales.
mod.order=Modificador ''{0}'' desordenado según las sugerencias de la JLS.
redundantModifier=Modificador ''{0}'' redundante.
interface.implied.modifier=El modificador impl\u00edcito debe ser expl\u00edcito: ''{0}''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should have these \u in the property files. Is there a reason you can't enter the actual characters into the file? Do the same for the other property files.

Copy link
Member

@romani romani Jun 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unicode symbols as is should be used.

@jodastephen , If you start to change your commit, please user Google translator to have non escaped symbols. In worst case we merge ugly translation, and other update it to better later on.

// private methods on interfaces are Java 9 only, but checkstyle is Java 8
// this test exists solely to provide coverage of private methods
final DetailAST modPrivate = new DetailAST();
modPrivate.setType(TokenTypes.LITERAL_PRIVATE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able create a valid Java 9 file and place it in non-compilable folder and put a marker on it that it should be compiled by Java 9.
Example: https://github.com/checkstyle/checkstyle/blob/master/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/grammars/java9/InputJava9TryWithResources.java#L1

@Override
public void visitToken(DetailAST ast) {
if (isInterfaceMember(ast)) {
if (ast.getType() == TokenTypes.METHOD_DEF) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a switch?

@@ -1,3 +1,4 @@
annotation.order=Annotation-Modifier ''{0}'' sollte vor den anderen Modifiern stehen.
mod.order=Modifier ''{0}'' weicht von der empfohlenen Modifier-Reihenfolge der Java Language Specification ab.
redundantModifier=Überflüssiger Modifier ''{0}''.
interface.implied.modifier=Impliziter Modifikator sollte explizit sein: ''{0}''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Bananeweizen , can you recheck this German translation.

@@ -1,3 +1,4 @@
annotation.order=Le modificateur d''annotation ''{0}'' ne précède pas les autres modificateurs.
mod.order=Le mot-clef ''{0}'' n''apparaît pas dans l''ordre préconisé par les JLS.
redundantModifier=Mot-clef ''{0}'' redondant.
interface.implied.modifier=Le modificateur implicite devrait \u00eatre explicite: ''{0}''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jajawah , is it good translation ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is ;)

@@ -1,3 +1,4 @@
annotation.order=''{0}'' 注釈修飾子は、非注釈修飾子に先行していません。
mod.order=''{0}'' 修飾子が JLS 提案の順序に沿いません。
redundantModifier=冗長な ''{0}'' 修飾子です。
interface.implied.modifier=\u6697\u793A\u3055\u308C\u305F\u4FEE\u98FE\u5B50\u306F\u660E\u793A\u7684\u306B\u3059\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059: ''{0}''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Nobuyuki-Inaba, please help us to make good Japanese translation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure. I'd appreciate if you could give me a few days to check it.
I found that existing messages are not unicode-escaped but the added message is unicode-escaped. If not unicode-escaped message allowed to use, I think not unicode-escaped should be used because not unicode-escaped message makes maintenance easy.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need not unicode-escaped, just to be easy to read by others. Thanks a lot in advance.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original message is OK but the below message sounds more natural in Japanese.
暗黙的な ''{0}'' 修飾子は明示的に指定すべきです。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -1,3 +1,4 @@
annotation.order=A anotação ''{0}'' não deveria preceder modificadores que não são anotações.
mod.order=O modificador ''{0}'' está fora da ordem sugerida pela JLS.
redundantModifier=O modificador ''{0}'' é redundante.
interface.implied.modifier=O modificador impl\u00edcito deve ser expl\u00edcito: ''{0}''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@victorwss, please help us good translation to Portuguese

@@ -5,3 +5,4 @@ annotation.order = ''{0}'' anotasyon niteleyicisi, anotasyon olmayan niteleyicil
mod.order = ''{0}'' niteleyicisi, Java tarafından önerilen sırada değil.

redundantModifier = Gereksiz ''{0}'' niteleyicisi.
interface.implied.modifier=Z\u0131mni de\u011Fi\u015Ftirici aç\u0131k olmal\u0131d\u0131r: ''{0}''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@precoder, it would be awesome is you can suggest Turkish translation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After reading the discussion link at the top of issue, I would suggest something like:
interface.implied.modifier=Varsayılan niteleyici: ''{0}'' açıkça belirtilmelidir.

@@ -1,3 +1,4 @@
annotation.order=注解 ''{0}'' 前不应有非注解修饰符。
mod.order=''{0}'' 修饰符顺序违反 JLS 建议.
redundantModifier=多余修饰符: ''{0}''。
interface.implied.modifier=\u9690\u542B\u7684\u4FEE\u9970\u7B26\u5E94\u8BE5\u662F\u660E\u786E\u7684: ''{0}''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Apache9, please help us with Chinese translation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Will take a look later today.

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jodastephen , thanks a lot for implementation.
I really impressed that passed pitest on first try :).

Passing CI is good, but not enough, we need prove that there are no exceptions on real life ugly projects.
Please read README of https://github.com/checkstyle/contribution/tree/master/checkstyle-tester
Please launch launch.groovy on all projects that are referenced in property file(just uncomment all). There should be no exceptions. Unfortunately there will be too much violations to share in web, so please select 1-3 projects you like(openjdkX is good candidate) and run report generation on them only and share it on github.io for us to review.
If you have any concerns or questions do not hesitate to ask us.

items to improve:


void method();

// cannot test private methods due to Java 8 baseline
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have java9 section in resources - https://github.com/checkstyle/checkstyle/tree/master/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/grammars/java9

just put a special comment to let CI verify that it actually compilable in java9.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove comment.

@@ -1,3 +1,4 @@
annotation.order=El modificador de anotación ''{0}'' no precede a los modificadores normales.
mod.order=Modificador ''{0}'' desordenado según las sugerencias de la JLS.
redundantModifier=Modificador ''{0}'' redundante.
interface.implied.modifier=El modificador impl\u00edcito debe ser expl\u00edcito: ''{0}''
Copy link
Member

@romani romani Jun 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unicode symbols as is should be used.

@jodastephen , If you start to change your commit, please user Google translator to have non escaped symbols. In worst case we merge ugly translation, and other update it to better later on.

<p>
Methods on interfaces are <code>public</code> by default, however from Java 9
they can also be <code>private</code>. This check provides the ability to enforce
that <code>public</code> is not implicitly added by the compiler.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather void phrases that we we enforce smth on compiler.
May it be better smth "enforce public be explicitly defined by human and not implicitly added by the compiler"
and in other places.

public interface AddressFactory {
// check enforces code contains "public static final"
public static final String UNKNOWN = "Unknown";

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update examples to have trailing comment "// violation" - it help users a lot to understand how Check works and what to expect from it.

// check enforces code contains "public static final"
public static final String UNKNOWN = "Unknown";
static final String UNKNOWN2 = "Unknown";   // violation

// check enforces code contains "public abstract"
public abstract Address createAddress(String addressLine, String city);

// check enforces code contains "public default" or "private"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is better to explain that we force "public" or "private".
"abstract" and "default" are enforced by compiler, not by checkstyle.

@jodastephen
Copy link
Contributor Author

Some issues addressed while I work towards the rest (Java 9 proving a problem). Key one is that the messages are now not unicode escapes.

@romani
Copy link
Member

romani commented Jun 28, 2018

Some issues addressed

It is better to reply "done" on each point we raised, to clearly track what is done and what is not. It will help us a lot.

@@ -1,3 +1,4 @@
annotation.order=A anotação ''{0}'' não deveria preceder modificadores que não são anotações.
interface.implied.modifier=O modificador implícito deve ser explícito: ''{0}''
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that O modificador implícito deveria ser explícito: ''{0}'' is a slightly better translation.

@victorwss
Copy link
Contributor

@romani The best translation to Portugueses would be O modificador implícito deveria ser explícito: ''{0}'' - However, the given translation is OK. Here, "deve" means "must", while "deveria" means "should".

BTW, I am not sure if \u-escaping those strings is a good idea. That makes non-ascii characters illegible and unrecognizable for humans. For far east languages, that makes the entire property files unintelligible and people would need to use some external tool to make any sense of them.

Nowadays, all those properties are already encoded without escaping, so picking one or other and encoding them in that way is not the right approach. We should use an all or nothing approach with that.

Digging further into this issue, unfortunately, the java.util.Properties.load(java.io.InputStream) method documentation state that properties should be encoded using the ISO-8859-1 encoding, which is a terrible stupid idea. But in Java 9, due to JEP 226, property files feature a hack to allow UTF-8 properties falling back to ISO-8859-1 if they're illegible in UTF-8.

The proper solution would be to use the java.util.Properties.load(java.io.Reader) method instead. IMO, the load(InputStream) method should have been deprecated because it is a hazard for proper internationalization.

I searched through Checkstyle's code and there is a lot of places which uses load(InputStream). There might be some other issues about encoding as well. I am already fixing them right now and I'll try to elaborate some sort of tests on this issue, perhaps using some emoji characters in property files and testing if they came out right after confirming that the old behaviour was broken in Java 8 or older. But this is something for other PR.

@romani
Copy link
Member

romani commented Jun 28, 2018

@victorwss

Digging further into this issue, unfortunately,

Please move this to separate issue.
Thanks a lot for translation.

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jodastephen , I know this is terrible bureaucracy, but please reply "done" for each point. You did emotion markers. But I do not receive notification on them so I could miss your changes for some time.

Regression testing is still required.

items to improve:

case TokenTypes.ENUM_DEF:
default:
processNestedType(ast);
break;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}
return parentTypeDef != null
&& parentTypeDef.getType() == TokenTypes.INTERFACE_DEF;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this getParents and checking for nulls looks suspicious.
Some gut filling tell me that we should use - https://github.com/checkstyle/checkstyle/blob/master/src/main/java/com/puppycrawl/tools/checkstyle/utils/ScopeUtil.java#L100
and be safe

Please also add to UT input cases like, and most likely in such case it is not public class, probably decompilation can say for sure:

$ cat Test.java 
interface Test
{
  default void test() {
    class A {}
  }
}
$ javac Test.java 
$ 

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All members of a package scoped interface are still public (output from javap):

Compiled from "InputInterfaceMemberImpliedModifierPackageScopeInterface.java"
interface com.puppycrawl.tools.checkstyle.checks.modifier.interfacememberimpliedmodifier.InputInterfaceMemberImpliedModifierPackageScopeInterface {
  public static final int fieldPublicStaticFinal;
  public static final int fieldPublicStatic;
  public static final int fieldPublicFinal;
  public static final int fieldPublic;
  public static final int fieldStaticFinal;
  public static final int fieldStatic;
  public static final int fieldFinal;
  public static final int field;
  public static void methodPublicStatic();
  public static void methodStatic();
  public void methodPublicDefault();
  public void methodDefault();
  public abstract void methodPublicAbstract();
  public abstract void methodAbstract();
  public abstract void methodPublic();
  public abstract void method();
}

Compiled from "InputInterfaceMemberImpliedModifierPackageScopeInterface.java"
public interface com.puppycrawl.tools.checkstyle.checks.modifier.interfacememberimpliedmodifier.InputInterfaceMemberImpliedModifierPackageScopeInterface$NestedInterface {
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ScopeUtil done

if (violateImpliedAbstractMethod
&& modifiers.findFirstToken(TokenTypes.LITERAL_STATIC) == null
&& modifiers.findFirstToken(TokenTypes.LITERAL_DEFAULT) == null
&& modifiers.findFirstToken(TokenTypes.LITERAL_PRIVATE) == null
Copy link
Member

@romani romani Jun 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move PRIVATE to the top of this group, to not mix visibility and "kind".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -1,3 +1,4 @@
annotation.order=''{0}'' 注釈修飾子は、非注釈修飾子に先行していません。
interface.implied.modifier=暗示された修飾子は明示的にする必要があります: ''{0}''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add , just to be consistent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -1,3 +1,4 @@
annotation.order=Annotation-Modifier ''{0}'' sollte vor den anderen Modifiern stehen.
interface.implied.modifier=Impliziter Modifikator sollte explizit sein: ''{0}''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please put period as in English.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

/**
* Tests Java 9 private method on interface.
*/
public class Java9PrivateMethodOnInterfaceTest extends AbstractModuleTestSupport {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please explain this intention to have separate test.
We usually never do like this, grammar tests are for checking AST structure only, not running any Checks.
probably we misleaded you.

You need to keep all UTs in one file.
create folder "modifiers/interfaceimpliedmodifier" at https://github.com/checkstyle/checkstyle/tree/master/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/checks
put InputJava9PrivateMethodOnInterface.java in new folder. Ones we migrate to jdk9 compilation, we will move all such inputs to regular location.

Example of test on non-compilable input - https://github.com/checkstyle/checkstyle/blob/master/src/test/java/com/puppycrawl/tools/checkstyle/checks/design/FinalClassCheckTest.java#L62

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a grammar test, so it shouldn't be here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


void method();

// cannot test private methods due to Java 8 baseline
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove comment.

<td>violateImpliedPublicField</td>
<td>
Control whether to enforce that <code>public</code> is not being implied by the
compiler on interface fields (true).</td>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is not being implied by the compiler on interface fields

Please void such phrases over compiler, lets phrase it as it is pure style demand.
Control whether to enforce that <code>public</code> is being explicitly defined or smth similar.
Please fix in other properties.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

<p> To configure the check: </p>
<source>
&lt;module name=&quot;InterfaceMemberImpliedModifier&quot;/&gt;
</source>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add here small snipped of code to show what behavior will be (with trailing comments "//violation")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

&lt;property name=&quot;violateImpliedPublicNested&quot; value=&quot;false&quot;/&gt;
&lt;property name=&quot;violateImpliedStaticNested&quot; value=&quot;false&quot;/&gt;
&lt;/module&gt;
</source>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add here small snipped of code to show what behavior will be (with trailing comments "//violation").

Unfortunately not that much good cases in our documentation to show you example, but user constantly complain about this. We try at least in new Checks enforce this good practice.

Good example: http://checkstyle.sourceforge.net/config_annotation.html#AnnotationLocation , there is human description, config, code example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jodastephen , I did not found case in inner class in method that I mentioned in comments.

item to resolve:

objBlock.addChild(init);
final DetailAST iface = new DetailAST();
iface.setType(TokenTypes.INTERFACE_DEF);
iface.addChild(objBlock);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://travis-ci.org/checkstyle/checkstyle/jobs/398313438#L672

please name it in better way "iface" ==> "interfaceAst"

CIs must pass.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@rnveach
Copy link
Member

rnveach commented Jun 30, 2018

@jodastephen See preferred japanese translation by speaker at #5974 (comment)

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

items to improve:


/**
* <p>
* Checks for implicit modifiers in interfaces.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is more precise:
"Checks for implicit modifiers on interface members and nested types."
if you agree please change here in all other plases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

* <ul>
* <li>
* Property {@code violateImpliedPublicField} - Control whether to enforce that {@code public}
* is explicitly coded and not implicitly added by the compiler on interface fields (true).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(true).

I am not sure what does this mean. If that is leftover from smth in past please remove (and in all other properties)

is explicitly coded

is explicitly coded on field

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jodastephen , I still see "(true)" .
Please keep replying "done" or some disagreement or .... on each review point. Please trust my experience it helps a lot.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

* </li>
* <li>
* Property {@code violateImpliedStaticField} - Control whether to enforce that {@code static}
* is explicitly coded and not implicitly added by the compiler on interface fields (true).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is explicitly coded ==> is explicitly coded on <smth> .
Please fix in all cases.

do not forget about xdoc.
unfortunately generation of xdoc by javadoc is not finished yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

* </li>
* </ul>
* <p>
* This example checks that methods, fields and nested types are explicitly specified
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checks that methods ...

checks that all implicit modifiers on methods ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


/**
* Control whether to enforce that {@code public} is explicitly coded and
* not implicitly added by the compiler on interface fields (true).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explicitly coded on field.

please fix all other places.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

public default boolean methodWithLocalClass(String input) {
class LocalClass {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from #5974 (review)

Passing CI is good, but not enough, we need prove that there are no exceptions on real life ugly projects.
Please read README of https://github.com/checkstyle/contribution/tree/master/checkstyle-tester
Please launch launch.groovy on all projects that are referenced in property file(just uncomment all). There should be no exceptions. Unfortunately there will be too much violations to share in web, so please select 1-3 projects you like(openjdkX is good candidate) and run report generation on them only and share it on github.io for us to review.
If you have any concerns or questions do not hesitate to ask us.

@rnveach
Copy link
Member

rnveach commented Jun 30, 2018

Since we released new version, any versions saying 8.11 in this PR needs to change to 8.12 .

@jodastephen
Copy link
Contributor Author

All comments addressed. But the regression suite doesn't seem to work:

[INFO] ------------------------------------------------------------------------
Running Checkstyle on src\main\java ... with excludes
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building sample 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-site-plugin:3.3:site (default-site) @ sample ---
[INFO] configuring report plugin org.apache.maven.plugins:maven-checkstyle-plugin:2.17
[INFO] configuring report plugin org.apache.maven.plugins:maven-jxr-plugin:2.5
[WARNING] Report plugin org.apache.maven.plugins:maven-project-info-reports-plugin has an empty version.
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[INFO] configuring report plugin org.apache.maven.plugins:maven-project-info-reports-plugin:3.0.0
[WARNING] Error injecting: org.apache.maven.report.projectinfo.CiManagementReport
java.lang.NoClassDefFoundError: org/apache/maven/doxia/siterenderer/DocumentContent
        at java.lang.Class.getDeclaredConstructors0(Native Method)
        at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
        at java.lang.Class.getDeclaredConstructors(Class.java:2020)
        at com.google.inject.spi.InjectionPoint.forConstructorOf(InjectionPoint.java:245)

I don't believe this is my changes - its not getting as far as running checkstyle.

Also, the checkstyle-tester project does not have instructions for running launch.groovy.

@romani
Copy link
Member

romani commented Jun 30, 2018

to fix appveyor or travis, it is required to rebase on latest master, I just pushed fix to master. Reason #5985

@romani
Copy link
Member

romani commented Jun 30, 2018

But the regression suite doesn't seem to work

I do not see your command to help, I am not sure what you launched.

Also, the checkstyle-tester project does not have instructions for running launch.groovy

please follow:
https://github.com/checkstyle/contribution/blob/master/checkstyle-tester/LAUNCH_GROOVY_README.md
I did:

checkstyle [master|✔] 
$ mvn clean install -Pno-validations
...
contribution/checkstyle-tester [master|✔] 
$ groovy launch.groovy -l projects-to-test-on.properties -c my_check.xml
...

do not forget to build SNAPSHOT from your branch, uncomment projects in projects-to-test-on.properties and use your Check in my_check.xml

@jodastephen
Copy link
Contributor Author

To get launch.groovy to work, I had to update mavens-site-plugin to the latest version in the pom.xml.

31 projects passed. It then failed in parsing. FWIW, I use Windows, mvn 3.5.0, Java 1.8.0_152:

guava-mvnstyle is synchronized
   [delete] Deleting directory D:\dev\contribution\checkstyle-tester\src\main\java
     [copy] Copying 3236 files to D:\dev\contribution\checkstyle-tester\src\main\java\guava-mvnstyle
Running 'mvn clean' on src\main\java ...
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building sample 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ sample ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.273 s
[INFO] Finished at: 2018-07-01T23:36:13+01:00
[INFO] Final Memory: 6M/123M
[INFO] ------------------------------------------------------------------------
Running Checkstyle on src\main\java ... with excludes **/guava-mvnstyle/**/test/**/*,**/guava-mvnstyle/guava-gwt/src-super/**/*,**/guava-mvnstyle/guava-gwt/test-super/**/*,**/guava-mvnstyle/guava-tests/**/*
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building sample 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-site-plugin:3.7.1:site (default-site) @ sample ---
[INFO] configuring report plugin org.apache.maven.plugins:maven-checkstyle-plugin:2.17
[INFO] 1 report detected for maven-checkstyle-plugin:2.17: checkstyle
[INFO] configuring report plugin org.apache.maven.plugins:maven-jxr-plugin:2.5
[INFO] 2 reports detected for maven-jxr-plugin:2.5: jxr, test-jxr
[WARNING] Report plugin org.apache.maven.plugins:maven-project-info-reports-plugin has an empty version.
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[INFO] configuring report plugin org.apache.maven.plugins:maven-project-info-reports-plugin:3.0.0
[INFO] 15 reports detected for maven-project-info-reports-plugin:3.0.0: ci-management, dependencies, dependency-info, dependency-management, distribution-management, index, issue-management, licenses, mailing-lists, modules, plugin-management, plugins, scm, summary, team
[INFO] Rendering site with default locale English (en)
[WARNING] No project URL defined - decoration links will not be relativized!
[INFO] Rendering content with org.apache.maven.skins:maven-default-skin:jar:1.2 skin.
[INFO] Generating "Checkstyle" report           --- maven-checkstyle-plugin:2.17:checkstyle
D:\dev\contribution\checkstyle-tester\src\main\java\guava-mvnstyle\guava\src\com\google\common\base\Objects.java:76:46: unexpected token: ...
D:\dev\contribution\checkstyle-tester\src\main\java\guava-mvnstyle\guava\src\com\google\common\base\Preconditions.java:161:23: unexpected token: ...
D:\dev\contribution\checkstyle-tester\src\main\java\guava-mvnstyle\guava\src\com\google\common\base\Strings.java:260:60: unexpected token: ...
D:\dev\contribution\checkstyle-tester\src\main\java\guava-mvnstyle\guava\src\com\google\common\base\Verify.java:122:33: unexpected token: ...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13.800 s
[INFO] Finished at: 2018-07-01T23:36:28+01:00
[INFO] Final Memory: 27M/386M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-site-plugin:3.7.1:site (default-site) on project sample: Error generating maven-checkstyle-plugin:2.17:checkstyle report: Failed during checkstyle execution: There are 4 errors reported by Checkstyle 8.12-SNAPSHOT with my_check.xml ruleset. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-site-plugin:3.7.1:site (default-site) on project sample: Error generating maven-checkstyle-plugin:2.17:checkstyle report
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:993)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:345)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:191)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Error generating maven-checkstyle-plugin:2.17:checkstyle report
        at org.apache.maven.plugins.site.render.SiteMojo.execute(SiteMojo.java:155)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
        ... 20 more
Caused by: org.apache.maven.reporting.MavenReportException: Failed during checkstyle execution
        at org.apache.maven.plugin.checkstyle.AbstractCheckstyleReport.executeReport(AbstractCheckstyleReport.java:492)
        at org.apache.maven.plugin.checkstyle.CheckstyleReport.executeReport(CheckstyleReport.java:154)
        at org.apache.maven.reporting.AbstractMavenReport.generate(AbstractMavenReport.java:255)
        at org.apache.maven.plugins.site.render.ReportDocumentRenderer.renderDocument(ReportDocumentRenderer.java:230)
        at org.apache.maven.doxia.siterenderer.DefaultSiteRenderer.render(DefaultSiteRenderer.java:349)
        at org.apache.maven.plugins.site.render.SiteMojo.renderLocale(SiteMojo.java:198)
        at org.apache.maven.plugins.site.render.SiteMojo.execute(SiteMojo.java:147)
        ... 22 more
Caused by: org.apache.maven.plugin.checkstyle.exec.CheckstyleExecutorException: There are 4 errors reported by Checkstyle 8.12-SNAPSHOT with my_check.xml ruleset.
        at org.apache.maven.plugin.checkstyle.exec.DefaultCheckstyleExecutor.executeCheckstyle(DefaultCheckstyleExecutor.java:313)
        at org.apache.maven.plugin.checkstyle.AbstractCheckstyleReport.executeReport(AbstractCheckstyleReport.java:473)
        ... 28 more
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Caught: groovy.lang.GroovyRuntimeException: Error: !
groovy.lang.GroovyRuntimeException: Error: !
        at launch.executeCmd(launch.groovy:310)
        at launch.executeCmd(launch.groovy:304)
        at launch$executeCmd$5.callCurrent(Unknown Source)
        at launch.runMavenExecution(launch.groovy:231)
        at launch$_generateCheckstyleReport_closure2.doCall(launch.groovy:91)
        at launch.generateCheckstyleReport(launch.groovy:70)
        at launch$generateCheckstyleReport$1.callCurrent(Unknown Source)
        at launch.run(launch.groovy:10)

Again, I don't think this is my code at fault. The regression process is very slow, so I don't have time now to run the script excluding this project. Maybe another day...

@romani
Copy link
Member

romani commented Jul 1, 2018

To get launch.groovy to work, I had to update mavens-site-plugin to the latest version in the pom.xml.

please share a problem on old version. I can not reproduce problem. It still works fine for me.

D:.....guava\src\com\google\common\base\Verify.java:122:33: unexpected token: ...

This almost always mean problems with java parsing or non-compilable source.

$ wget https://raw.githubusercontent.com/google/guava/master/guava/src/com/google/common/base/Verify.java

$ java -jar checkstyle-8.10.1-all.jar -c /google_checks.xml Verify.java
Starting audit...
/var/tmp/Verify.java:122:33: unexpected token: ...
com.puppycrawl.tools.checkstyle.api.CheckstyleException: Exception was thrown while processing Verify.java
	at com.puppycrawl.tools.checkstyle.Checker.processFiles(Checker.java:295)
	at com.puppycrawl.tools.checkstyle.Checker.process(Checker.java:213)
	at com.puppycrawl.tools.checkstyle.Main.runCheckstyle(Main.java:554)
	at com.puppycrawl.tools.checkstyle.Main.runCli(Main.java:465)
	at com.puppycrawl.tools.checkstyle.Main.main(Main.java:219)
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: MismatchedTokenException occurred while parsing file /var/tmp/Verify.java.
	at com.puppycrawl.tools.checkstyle.JavaParser.parse(JavaParser.java:98)
	at com.puppycrawl.tools.checkstyle.TreeWalker.processFiltered(TreeWalker.java:180)
	at com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck.process(AbstractFileSetCheck.java:81)
	at com.puppycrawl.tools.checkstyle.Checker.processFile(Checker.java:316)
	at com.puppycrawl.tools.checkstyle.Checker.processFiles(Checker.java:286)
	... 4 more
Caused by: /var/tmp/Verify.java:125:5: expecting EOF, found '}'
	at antlr.Parser.match(Parser.java:211)
	at com.puppycrawl.tools.checkstyle.grammars.GeneratedJavaRecognizer.compilationUnit(GeneratedJavaRecognizer.java:211)
	at com.puppycrawl.tools.checkstyle.JavaParser.parse(JavaParser.java:92)
	... 8 more
Checkstyle ends with 1 errors.

# download same file but for 18.0 version that is referenced in property file
$ wget https://raw.githubusercontent.com/google/guava/798803f026bb9517bcf4e0e9ab2d2e0345023182/guava/src/com/google/common/base/Verify.java

$ java -jar checkstyle-8.10.1-all.jar -c /google_checks.xml Verify.java
Starting audit...
[WARN] /var/tmp/Verify.java:82: Empty line should be followed by <p> tag on the next line. [JavadocParagraph]
Audit done.

you run into existing problem in our parser - #3238 (comment)
Please change in you property file https://github.com/checkstyle/contribution/blob/master/checkstyle-tester/projects-to-test-on.properties#L53 master to v25.0
this was changed recently https://github.com/google/guava/blame/86eabf1fe6991cf7fbc65980dac59a604303b362/guava/src/com/google/common/base/Verify.java#L122
I updated contribution repo too.

Please run again.

@romani
Copy link
Member

romani commented Jul 2, 2018

@jodastephen ,

To get launch.groovy to work, I had to update mavens-site-plugin to the latest version in the pom.xml.

did you run into the same issue as have today in our CIs - checkstyle/contribution#316 , if yes, please grab latest from our contributions repo. I pushed fixes, launch.groovy should work.

@romani
Copy link
Member

romani commented Jul 2, 2018

@jodastephen , please update Chinese translation as suggested at #5974 (comment)

@jodastephen
Copy link
Contributor Author

@romani
Copy link
Member

romani commented Jul 3, 2018

@jodastephen , thanks a lot. While we do final reviews, please run launch.groovy one more time on all projects in properties BUT with severity "ignore", it will generate empty report if no exceptions found. No need to share such report. Just confirm in comment that there are no exceptions.

Please also add your new Check to https://github.com/checkstyle/contribution/blob/master/checkstyle-tester/checks-nonjavadoc-error.xml by PR, we will merge such PR after release, and your Check will be in automatic regression execution.

@romani
Copy link
Member

romani commented Jul 4, 2018

@rnveach , please do final review, please pay attention to documentation , as it was main problem for us from the beginning.

reports looks good, I did random recheck for about 30 cases (for static, final, public), all looks good.

Codacy/PR Quality Review

this is false positive.
@rnveach , in report page it show that it is running under you user https://app.codacy.com/app/rveach02/checkstyle . Did you setup this service ?

@jodastephen
Copy link
Contributor Author

  • Rebased code to latest on master (no code/text changes)
  • Built locally
  • Ran launch.groovy with severity ignore
  • No exceptions (on command line or in report files)

Thanks

* specified even though they are actually redundant.
* </p>
* <p>
* Methods on interfaces are {@code public} by default, however from Java 9 they can also be
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Methods on interfaces => Methods in interfaces
These things are in the interface, not on top of them.
later on you use within. that is acceptable too for all these.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

* coded and not implicitly added by the compiler.
* </p>
* <p>
* From Java 8, there are three types of methods on interfaces - static methods marked with
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

methods on interfaces => methods in interfaces

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

* explicitly coded and not implicitly added by the compiler.
* </p>
* <p>
* Fields on interfaces are always {@code public static final} and as such the compiler does not
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fields on interfaces => Fields in interfaces

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

* }
* </pre>
* <p>
* Rationale for these checks: Methods, fields and nested types are treated differently
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these checks? plural? You never specify more than this check, so I think the rationale should only pertain to this check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

* default methods are package-scoped on classes, but public on interfaces. However, from
* Java 8 onwards, interfaces have changed to be much more like abstract classes.
* Interfaces now have static and instance methods with code. Developers should not have to
* remember which modifiers are required and which are implicit. This check allows the simpler
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which are implicit => which are implied
implicit is an adjective and you are using it as a verb in this scenario.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

* </ul>
* <p>
* This example checks that all implicit modifiers on methods, fields and nested
* types are explicitly specified on interfaces.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

specified on interfaces => specified inside interfaces

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

/**
* Check method on interface.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check method on interface => Checks method in interface

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

/**
* Check field on interface.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check field on interface => Checks field in interface

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


/**
* Check field on interface.
* @param ast method AST
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

method AST => field AST

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

/**
* Check nested types on interface.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check nested types on interface => Checks nested type in interface

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@rnveach
Copy link
Member

rnveach commented Jul 6, 2018

@romani Feel free to look over this one last time before merging.

@romani romani merged commit 327b556 into checkstyle:master Jul 6, 2018
@romani
Copy link
Member

romani commented Jul 6, 2018

@jodastephen , thanks a lot for close collaboration, 9 days for PR acceptable for new module, it is pretty quick result.

@romani
Copy link
Member

romani commented Jul 6, 2018

Thanks a lot to all translation participants, we appreciate your help and hope you will enjoy new validations in native languages.

@jodastephen jodastephen deleted the issue5899 branch July 6, 2018 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants