Skip to content

Commit

Permalink
Issue checkstyle#3177: Avoid catching of run-time exception
Browse files Browse the repository at this point in the history
  • Loading branch information
MEZk committed Jun 8, 2016
1 parent 6155da6 commit 6ac01ce
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import java.net.URI;
import java.nio.file.AccessDeniedException;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.MessageDigest;
Expand Down Expand Up @@ -144,7 +143,7 @@ public void persist() throws IOException {
Files.createDirectories(directory);
}
}
catch (InvalidPathException | AccessDeniedException ex) {
catch (AccessDeniedException ex) {
throw new IllegalStateException(ex.getMessage(), ex);
}
FileOutputStream out = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package com.puppycrawl.tools.checkstyle;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.core.StringEndsWith.endsWith;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand All @@ -40,7 +39,6 @@
import java.lang.reflect.Method;
import java.nio.file.AccessDeniedException;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Paths;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
Expand Down Expand Up @@ -137,21 +135,6 @@ public void testPathToCacheContainsOnlyFileName() throws IOException {
}
}

@Test
public void testPathToCacheFileContainsIllegalCharacters() throws IOException {
final Configuration config = new DefaultConfiguration("myName");
final String filePath = "\\\0:FOO\\server.properties";
final PropertyCacheFile cache = new PropertyCacheFile(config, filePath);
try {
cache.persist();
fail("Exception is expected!");
}
catch (IllegalStateException ex) {
assertThat(ex.getCause(), instanceOf(InvalidPathException.class));
assertThat(ex.getMessage(), endsWith("server.properties"));
}
}

@Test
public void testNonAccessibleDirectory() throws Exception {

Expand Down

0 comments on commit 6ac01ce

Please sign in to comment.