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

WhitespaceAfterCheck: problem with multiline typecast #3850

Closed
rwalkerands opened this Issue Feb 22, 2017 · 5 comments

Comments

Projects
None yet
3 participants
@rwalkerands

rwalkerands commented Feb 22, 2017

/var/tmp $ javac an/extremelylongpackagenamethat/hasmultiplecomponents/Test.java
/var/tmp $ cat an/extremelylongpackagenamethat/hasmultiplecomponents/Test.java

package an.extremelylongpackagenamethat.hasmultiplecomponents;

public class Test {

    public static void main(String args[]) {
        Test test =
            new an.extremelylongpackagenamethat.hasmultiplecomponents.Test();
        Test test2 = (an.extremelylongpackagenamethat.hasmultiplecomponents.
                 Test) test;
    }

}

/var/tmp $ cat config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="Checker">
  <property name="severity" value="warning"/>
  <module name="TreeWalker">
    <module name="WhitespaceAfter"/>
  </module>
</module>

/var/tmp $ java -jar checkstyle-7.5.1-all.jar -c config.xml an/extremelylongpackagenamethat/hasmultiplecomponents/Test.java

Starting audit...
[WARN] /private/var/tmp/an/extremelylongpackagenamethat/hasmultiplecomponents/Test.java:9:23: 'typecast' is not followed by whitespace. [WhitespaceAfter]
Audit done.

Describe what you expect in detail.

I expect no warning. There is whitespace after the cast. The check seems to get confused by the fact that there is a line break in the cast. I have to have a line break in order to keep the line under 80 characters.


@rnveach

This comment has been minimized.

Show comment
Hide comment
@rnveach

rnveach Feb 22, 2017

Member

@romani This looks valid. When we first receive the token, we capture the line we are dealing with and this is the line we use to validate against for whitespaces.
Unfortunately TYPECAST is a special case where we use a different token to validate against and we don't update the line. The token we are now examining is on a different line, and this causes the false violation.

Had the user had 1 extra space in the place we are looking on the previous line (line 7), no violation would have shown.

$ cat TestClass.java
package test;

public class TestClass {
    public void test() {
        Test test =
                new an.extremelylongpackagenamethat.hasmultiplecomponents.Test();
        Test test2 =  (an.extremelylongpackagenamethat.hasmultiplecomponents.
                 Test) test;
    }
}


$ 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">
    <property name="charset" value="UTF-8"/>

    <module name="TreeWalker">
    </module>
</module>

$ java -jar checkstyle-7.5.1-all.jar -c TestConfig.xml TestClass.java
Starting audit...
Audit done.
Member

rnveach commented Feb 22, 2017

@romani This looks valid. When we first receive the token, we capture the line we are dealing with and this is the line we use to validate against for whitespaces.
Unfortunately TYPECAST is a special case where we use a different token to validate against and we don't update the line. The token we are now examining is on a different line, and this causes the false violation.

Had the user had 1 extra space in the place we are looking on the previous line (line 7), no violation would have shown.

$ cat TestClass.java
package test;

public class TestClass {
    public void test() {
        Test test =
                new an.extremelylongpackagenamethat.hasmultiplecomponents.Test();
        Test test2 =  (an.extremelylongpackagenamethat.hasmultiplecomponents.
                 Test) test;
    }
}


$ 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">
    <property name="charset" value="UTF-8"/>

    <module name="TreeWalker">
    </module>
</module>

$ java -jar checkstyle-7.5.1-all.jar -c TestConfig.xml TestClass.java
Starting audit...
Audit done.
@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Feb 23, 2017

Member

@rnveach , workaround is funny.

issue is approved.

@rwalkerands , please be welcome to provide the fix, as this case is so rear.

Member

romani commented Feb 23, 2017

@rnveach , workaround is funny.

issue is approved.

@rwalkerands , please be welcome to provide the fix, as this case is so rear.

@romani romani added the approved label Feb 23, 2017

@rwalkerands

This comment has been minimized.

Show comment
Hide comment
@rwalkerands

rwalkerands Feb 23, 2017

Adding a space at the end of a line is not possible for me, otherwise -- with my actual configuration (based on Sun checks) -- I get a warning about trailing whitespace. (And I have Eclipse configured to remove it on save, anyway.)

Adding a space at the end of a line is not possible for me, otherwise -- with my actual configuration (based on Sun checks) -- I get a warning about trailing whitespace. (And I have Eclipse configured to remove it on save, anyway.)

@rwalkerands

This comment has been minimized.

Show comment
Hide comment
@rwalkerands

rwalkerands Feb 23, 2017

Oh sorry, misread it completely. I now see where the space is. Indeed, it raised an eyebrow.

Oh sorry, misread it completely. I now see where the space is. Indeed, it raised an eyebrow.

soon added a commit to soon/checkstyle that referenced this issue Mar 1, 2017

soon added a commit to soon/checkstyle that referenced this issue Mar 1, 2017

soon added a commit to soon/checkstyle that referenced this issue Mar 1, 2017

soon added a commit to soon/checkstyle that referenced this issue Mar 1, 2017

soon added a commit to soon/checkstyle that referenced this issue Mar 1, 2017

soon added a commit to soon/checkstyle that referenced this issue Mar 1, 2017

soon added a commit to soon/checkstyle that referenced this issue Mar 1, 2017

soon added a commit to soon/checkstyle that referenced this issue Mar 1, 2017

soon added a commit to soon/checkstyle that referenced this issue Mar 2, 2017

romani added a commit that referenced this issue Mar 3, 2017

@romani romani added the bug label Mar 3, 2017

@romani romani added this to the 7.7 milestone Mar 3, 2017

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Mar 3, 2017

Member

Fix is merged

Member

romani commented Mar 3, 2017

Fix is merged

@romani romani closed this Mar 3, 2017

@romani romani changed the title from WhitespaceAfterCheck to WhitespaceAfterCheck: problem with multiline typecast Mar 26, 2017

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