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

Pull #3841: add allowEmptyCatches parameter to WhitespaceAroundCheck #3841

Merged
merged 1 commit into from Feb 20, 2017

Conversation

Projects
None yet
4 participants
@liscju
Contributor

liscju commented Feb 18, 2017

It should be an option to disable checking whitespace around empty catch block because:

try {
 sth....
} catch (RuntimeException ex) {}

is a common pattern to explicitly suppress exceptions.

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Feb 18, 2017

Member

why this Check does not help you
http://checkstyle.sourceforge.net/config_blocks.html#EmptyCatchBlock ?

catch token could be removed from http://checkstyle.sourceforge.net/config_whitespace.html#WhitespaceAround in config if EmptyCatchBlock exists

Member

romani commented Feb 18, 2017

why this Check does not help you
http://checkstyle.sourceforge.net/config_blocks.html#EmptyCatchBlock ?

catch token could be removed from http://checkstyle.sourceforge.net/config_whitespace.html#WhitespaceAround in config if EmptyCatchBlock exists

@codecov-io

This comment has been minimized.

Show comment
Hide comment
@codecov-io

codecov-io Feb 18, 2017

Codecov Report

Merging #3841 into master will not change coverage.
The diff coverage is 100%.

@@          Coverage Diff           @@
##           master   #3841   +/-   ##
======================================
  Coverage     100%    100%           
======================================
  Files         275     275           
  Lines       13644   13648    +4     
  Branches     3070    3072    +2     
======================================
+ Hits        13644   13648    +4
Impacted Files Coverage Δ
...style/checks/whitespace/WhitespaceAroundCheck.java 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 29af968...63a6810. Read the comment docs.

codecov-io commented Feb 18, 2017

Codecov Report

Merging #3841 into master will not change coverage.
The diff coverage is 100%.

@@          Coverage Diff           @@
##           master   #3841   +/-   ##
======================================
  Coverage     100%    100%           
======================================
  Files         275     275           
  Lines       13644   13648    +4     
  Branches     3070    3072    +2     
======================================
+ Hits        13644   13648    +4
Impacted Files Coverage Δ
...style/checks/whitespace/WhitespaceAroundCheck.java 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 29af968...63a6810. Read the comment docs.

liscju added a commit to liscju/checkstyle that referenced this pull request Feb 18, 2017

@liscju

This comment has been minimized.

Show comment
Hide comment
@liscju

liscju Feb 18, 2017

Contributor

I want to check whitespace around left and right curly brackets, to do this i need to add SLIST to list of tokens (because in WHILE,FOR,etc SLIST "represents" left curly bracket). This works for all cases beside:

try {
 sth....
} catch (RuntimeException ex) {}

This case raises violation because left curly bracket is not separated from right by whitespace. I want to supress violation in this case.

Removing catch token from list of tokens does not help, because problem with SLIST persist. Thats why EmptyCatchBlock has nothing to do with this case.

Contributor

liscju commented Feb 18, 2017

I want to check whitespace around left and right curly brackets, to do this i need to add SLIST to list of tokens (because in WHILE,FOR,etc SLIST "represents" left curly bracket). This works for all cases beside:

try {
 sth....
} catch (RuntimeException ex) {}

This case raises violation because left curly bracket is not separated from right by whitespace. I want to supress violation in this case.

Removing catch token from list of tokens does not help, because problem with SLIST persist. Thats why EmptyCatchBlock has nothing to do with this case.

Show outdated Hide outdated ...crawl/tools/checkstyle/checks/whitespace/InputWhitespaceAroundCatch.java
int k = 1;
try {
k = 5 / i;
} catch (ArithmeticException ex) {}

This comment has been minimized.

@romani

romani Feb 18, 2017

Member

please make test cases with space in braces, empty line, comment.

@romani

romani Feb 18, 2017

Member

please make test cases with space in braces, empty line, comment.

This comment has been minimized.

@liscju

liscju Feb 19, 2017

Contributor

DONE

@liscju

liscju Feb 19, 2017

Contributor

DONE

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Feb 18, 2017

Member

Removing catch token from list of tokens does not help, because problem with SLIST persist. Thats why EmptyCatchBlock has nothing to do with this case.

please add this to xdoc to deliver that nuance to user. It will be useful.

Member

romani commented Feb 18, 2017

Removing catch token from list of tokens does not help, because problem with SLIST persist. Thats why EmptyCatchBlock has nothing to do with this case.

please add this to xdoc to deliver that nuance to user. It will be useful.

@liscju

This comment has been minimized.

Show comment
Hide comment
@liscju

liscju Feb 18, 2017

Contributor

please add this to xdoc to deliver that nuance to user. It will be useful.

I have problem how to formulate this in transparent manner, any suggestions?

Contributor

liscju commented Feb 18, 2017

please add this to xdoc to deliver that nuance to user. It will be useful.

I have problem how to formulate this in transparent manner, any suggestions?

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Feb 18, 2017

Member

Do smth. I will review and provide suggestions .

Member

romani commented Feb 18, 2017

Do smth. I will review and provide suggestions .

liscju added a commit to liscju/checkstyle that referenced this pull request Feb 19, 2017

@liscju

This comment has been minimized.

Show comment
Hide comment
@liscju

liscju Feb 19, 2017

Contributor

Do smth. I will review and provide suggestions .

I included explanation in xdoc. I have no idea why wercker/build failed, i cant check this because of authorization error.

Contributor

liscju commented Feb 19, 2017

Do smth. I will review and provide suggestions .

I included explanation in xdoc. I have no idea why wercker/build failed, i cant check this because of authorization error.

@rnveach

This comment has been minimized.

Show comment
Hide comment
@rnveach

rnveach Feb 19, 2017

Member

werker failure is unrelated. an external website we regression check against is down.

Member

rnveach commented Feb 19, 2017

werker failure is unrelated. an external website we regression check against is down.

</p>
<p>This check does not flag as violation double brace initialization like:</p>
<pre><code>
new Properties() {{
setProperty("key", "value");
}};
</code></pre>
<p>Parameter allowEmptyCatches allows to suppress violations when token
list contains SLIST to check if beginning of block is surrounded by

This comment has been minimized.

@rnveach

rnveach Feb 19, 2017

Member

I don't think we should mention SLIST or token types in description documentation. User may not be familiar with our tokens and tree structure. It should just explain java code.
We should stick to catch blocks and it's braces.

@rnveach

rnveach Feb 19, 2017

Member

I don't think we should mention SLIST or token types in description documentation. User may not be familiar with our tokens and tree structure. It should just explain java code.
We should stick to catch blocks and it's braces.

This comment has been minimized.

@liscju

liscju Feb 19, 2017

Contributor

I added this because of @romani suggestion:

Removing catch token from list of tokens does not help, because problem with SLIST persist. Thats why EmptyCatchBlock has nothing to do with this case.

please add this to xdoc to deliver that nuance to user. It will be useful.

In my view parameter is so self explanatory it does not need an example, and issue with SLIST is a subset of general problem with empty catch blocks in WhitespaceAround check.

@liscju

liscju Feb 19, 2017

Contributor

I added this because of @romani suggestion:

Removing catch token from list of tokens does not help, because problem with SLIST persist. Thats why EmptyCatchBlock has nothing to do with this case.

please add this to xdoc to deliver that nuance to user. It will be useful.

In my view parameter is so self explanatory it does not need an example, and issue with SLIST is a subset of general problem with empty catch blocks in WhitespaceAround check.

This comment has been minimized.

@rnveach

rnveach Feb 20, 2017

Member

This can be ignored then.

@rnveach

rnveach Feb 20, 2017

Member

This can be ignored then.

Show outdated Hide outdated src/xdocs/config_whitespace.xml
k = 5 / i;
} catch (ArithmeticException ex) {}
</code></pre>
Without this parameter this raises violation because the beginning of the

This comment has been minimized.

@rnveach

rnveach Feb 19, 2017

Member

Reword:
With this property turned off, this raises...

@rnveach

rnveach Feb 19, 2017

Member

Reword:
With this property turned off, this raises...

This comment has been minimized.

@liscju

liscju Feb 19, 2017

Contributor

Ok

@liscju

liscju Feb 19, 2017

Contributor

Ok

@romani

romani approved these changes Feb 19, 2017

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Feb 19, 2017

Member

I am fine with code.

@liscju , please provide diff-testing with your new option. Diff tool - https://github.com/checkstyle/contribution/blob/master/checkstyle-tester/diff.groovy , https://github.com/checkstyle/contribution/blob/master/checkstyle-tester/README.md .

base reports is just this Check before fix, patch report is new code and new option is used. Please review report your self before sharing it with us.

@rnveach , please finish/approve code review.

Member

romani commented Feb 19, 2017

I am fine with code.

@liscju , please provide diff-testing with your new option. Diff tool - https://github.com/checkstyle/contribution/blob/master/checkstyle-tester/diff.groovy , https://github.com/checkstyle/contribution/blob/master/checkstyle-tester/README.md .

base reports is just this Check before fix, patch report is new code and new option is used. Please review report your self before sharing it with us.

@rnveach , please finish/approve code review.

@liscju

This comment has been minimized.

Show comment
Hide comment
@liscju

liscju Feb 20, 2017

Contributor

All changes i checked in report after deals with lack of violation in empty catch blocks like:

} catch (RuntimeException ex) {}

Report can be found in: https://liscju.bitbucket.io/reports/diff/guava/index.html

Contributor

liscju commented Feb 20, 2017

All changes i checked in report after deals with lack of violation in empty catch blocks like:

} catch (RuntimeException ex) {}

Report can be found in: https://liscju.bitbucket.io/reports/diff/guava/index.html

@romani romani merged commit dac58b6 into checkstyle:master Feb 20, 2017

6 of 7 checks passed

wercker/build Wercker pipeline failed
Details
IDEA Inspections Pull Request (Checkstyle) TeamCity build finished
Details
codacy/pr Good work! A positive pull request.
Details
codecov/patch 100% of diff hit (target 100%)
Details
codecov/project 100% (+0%) compared to 29af968
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@romani romani added this to the 7.6 milestone Feb 20, 2017

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