From be8b1ceab13b66a556583cbff85456039e3e8b41 Mon Sep 17 00:00:00 2001 From: Oliver Burn Date: Sun, 23 Oct 2011 15:39:38 +1100 Subject: [PATCH] Add a test demostrating bug in indentation check --- .../InputValidTryResourcesIndent.java | 21 +++++++++++++++++++ .../indentation/IndentationCheckTest.java | 12 +++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/testinputs/com/puppycrawl/tools/checkstyle/indentation/InputValidTryResourcesIndent.java diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/indentation/InputValidTryResourcesIndent.java b/src/testinputs/com/puppycrawl/tools/checkstyle/indentation/InputValidTryResourcesIndent.java new file mode 100644 index 000000000..c8ef57cb6 --- /dev/null +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/indentation/InputValidTryResourcesIndent.java @@ -0,0 +1,21 @@ +package com.puppycrawl.tools.checkstyle.indentation; + +import java.io.FileInputStream; +import java.io.IOException; +import java.util.jar.JarInputStream; +import java.util.jar.Manifest; + +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)) + { + return jis.getManifest(); + } catch (IOException e) + { + return null; + } + } +} 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 cb3ed7b86..86ac78dd7 100755 --- a/src/tests/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckTest.java +++ b/src/tests/com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckTest.java @@ -731,4 +731,16 @@ public class IndentationCheckTest extends BaseCheckTestSupport final String[] expected = {}; verify(checkConfig, getPath("Input15Extensions.java"), expected); } + + @Test + public void testTryResources() throws Exception + { + final DefaultConfiguration checkConfig = + createCheckConfig(IndentationCheck.class); + final String[] expected = { + "something is expected, but there is a NullPointerException", + }; + verify(checkConfig, getPath("indentation/InputValidTryResourcesIndent.java"), + expected); + } }