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

IllegalType: update documentation to make it clear that LITERAL_NEW is not a target of this Check #5129

Closed
sergileon opened this Issue Sep 20, 2017 · 2 comments

Comments

Projects
None yet
3 participants
@sergileon
Contributor

sergileon commented Sep 20, 2017

http://checkstyle.sourceforge.net/config_coding.html#IllegalType

$ javac Test.java

$ cat Test.java

class Test{
  public Object foo(){
    return new Boolean(true);
  }
}

$ cat config.xml

<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
          "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name = "Checker">
    <module name="TreeWalker">
        <module name="IllegalTypeCheck">
            <property name="illegalClassNames" value="Boolean"/>
        </module>
    </module>
</module>

$ java -jar checkstyle-8.3-SNAPSHOT-all.jar -c config.xml Test.java

Starting audit...
Audit done.

Expected:
[ERROR] Test.java:3:16: Declaring variables, return values or parameters of type 'Boolean' is not allowed. [IllegalType]

@rnveach

This comment has been minimized.

Show comment
Hide comment
@rnveach

rnveach Sep 20, 2017

Member

http://checkstyle.sourceforge.net/config_coding.html#IllegalType

classes are never used as types in variable declarations, return values or parameters.

new Boolean(true);

Technically, this isn't a type. It is an instantiation, and you should probably use IllegalInstantiation over IllegalType.

$ cat TestClass.java
class Test{
  public Object foo(){
    return new Boolean(true);
  }
}

$ cat TestConfig.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
          "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name = "Checker">
    <module name="TreeWalker">
        <module name="IllegalInstantiation">
            <property name="classes" value="Boolean"/>
        </module>
    </module>
</module>

$ java -jar checkstyle-8.2-all.jar -c TestConfig.xml TestClass.java
Starting audit...
[ERROR] TestClass.java:3:12: Instantiation of Boolean should be avoided. [IllegalInstantiation]
Audit done.
Checkstyle ends with 1 errors.
Member

rnveach commented Sep 20, 2017

http://checkstyle.sourceforge.net/config_coding.html#IllegalType

classes are never used as types in variable declarations, return values or parameters.

new Boolean(true);

Technically, this isn't a type. It is an instantiation, and you should probably use IllegalInstantiation over IllegalType.

$ cat TestClass.java
class Test{
  public Object foo(){
    return new Boolean(true);
  }
}

$ cat TestConfig.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
          "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name = "Checker">
    <module name="TreeWalker">
        <module name="IllegalInstantiation">
            <property name="classes" value="Boolean"/>
        </module>
    </module>
</module>

$ java -jar checkstyle-8.2-all.jar -c TestConfig.xml TestClass.java
Starting audit...
[ERROR] TestClass.java:3:12: Instantiation of Boolean should be avoided. [IllegalInstantiation]
Audit done.
Checkstyle ends with 1 errors.

@romani romani changed the title from IllegalType for LITERAL_NEW to IllegalType: update documentation to make it clear that LITERAL_NEW is not a target of this Check Sep 21, 2017

romani added a commit that referenced this issue Sep 21, 2017

Issue #5129: update documentation to make it clear that LITERAL_NEW i…
…s not a target of this IllegalType Check

@romani romani added the approved label Sep 21, 2017

@romani romani added this to the 8.3 milestone Sep 21, 2017

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Sep 21, 2017

Member

fix for documentation is merged

Member

romani commented Sep 21, 2017

fix for documentation is merged

@romani romani closed this Sep 21, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment