From b441a1e751faa8d706dbb85d45273bff4f465c6d Mon Sep 17 00:00:00 2001 From: Oliver Burn Date: Sat, 29 Oct 2011 20:23:37 +1100 Subject: [PATCH] Apply patch from Dinesh Bolkensteyn to fix the NPE. The indentation check should still be reporting an error in the tryBlock. --- .../com/puppycrawl/tools/checkstyle/grammars/java.g | 7 ++++++- .../indentation/InputValidTryResourcesIndent.java | 3 ++- .../checks/indentation/IndentationCheckTest.java | 3 +-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/grammars/java.g b/src/checkstyle/com/puppycrawl/tools/checkstyle/grammars/java.g index ad96679f4..c2a8cb6da 100755 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/grammars/java.g +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/grammars/java.g @@ -1146,9 +1146,14 @@ resources {#resources = #([RESOURCES, "RESOURCES"], #resources);} ; + resource - : modifiers typeSpec[true] IDENT ASSIGN expression + : modifiers typeSpec[true] IDENT resource_assign {#resource = #([RESOURCE, "RESOURCE"], #resource);} +; + +resource_assign + : ASSIGN^ expression ; // an exception handler diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/indentation/InputValidTryResourcesIndent.java b/src/testinputs/com/puppycrawl/tools/checkstyle/indentation/InputValidTryResourcesIndent.java index 07d99f053..5b5fd93da 100644 --- a/src/testinputs/com/puppycrawl/tools/checkstyle/indentation/InputValidTryResourcesIndent.java +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/indentation/InputValidTryResourcesIndent.java @@ -11,7 +11,8 @@ class InputValidTryResourcesIndent // Taken from JDK7 java.lang.Package src code. private static Manifest loadManifest(String fn) { try (FileInputStream fis = new FileInputStream(fn); -JarInputStream jis = new JarInputStream(fis, false)) + // This should be an error + JarInputStream jis = new JarInputStream(fis, false)) { return jis.getManifest(); } catch (IOException e) diff --git a/src/tests/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckTest.java b/src/tests/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckTest.java index 5931b7484..164c3f7d4 100755 --- a/src/tests/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckTest.java +++ b/src/tests/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckTest.java @@ -734,13 +734,12 @@ public class IndentationCheckTest extends BaseCheckTestSupport } @Test - @Ignore public void testTryResources() throws Exception { final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class); final String[] expected = { - "something is expected, but there is a NullPointerException", + //"something is expected, but there is nothing", }; verify(checkConfig, getPath("indentation/InputValidTryResourcesIndent.java"), expected);