Remove unthrown exceptions.

This commit is contained in:
Karsten Loesing 2018-08-20 14:47:34 +02:00
parent 3ba8bdcc16
commit cfd3aecaf7
18 changed files with 24 additions and 37 deletions

View File

@ -61,7 +61,7 @@ public class Main {
* At most one argument.
* See class description {@link Main}.
*/
public static void main(String[] args) throws Exception {
public static void main(String[] args) {
try {
Path confPath = null;
if (args == null || args.length == 0) {

View File

@ -3,8 +3,6 @@
package org.torproject.metrics.collector.bridgedescs;
import org.torproject.metrics.collector.conf.ConfigurationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -32,7 +30,7 @@ public class BridgeDescriptorParser {
/** Parses the first line of the given descriptor data to determine the
* descriptor type and passes it to the sanitized bridges writer. */
public void parse(byte[] allData, String dateTime,
String authorityFingerprint) throws ConfigurationException {
String authorityFingerprint) {
try {
BufferedReader br = new BufferedReader(new StringReader(
new String(allData, "US-ASCII")));

View File

@ -440,8 +440,7 @@ public class SanitizedBridgesWriter extends CollecTorMain {
* Sanitizes a network status and writes it to disk.
*/
public void sanitizeAndStoreNetworkStatus(byte[] data,
String publicationTime, String authorityFingerprint)
throws ConfigurationException {
String publicationTime, String authorityFingerprint) {
if (this.persistenceProblemWithSecrets) {
/* There's a persistence problem, so we shouldn't scrub more IP

View File

@ -194,7 +194,7 @@ public class ExitListDownloader extends CollecTorMain {
/** Delete all files from the rsync directory that have not been modified
* in the last three days. */
public void cleanUpRsyncDirectory() throws ConfigurationException {
public void cleanUpRsyncDirectory() {
long cutOffMillis = System.currentTimeMillis()
- 3L * 24L * 60L * 60L * 1000L;
Stack<File> allFiles = new Stack<>();

View File

@ -8,7 +8,6 @@ import org.torproject.descriptor.index.FileNode;
import org.torproject.descriptor.index.IndexNode;
import org.torproject.descriptor.internal.FileType;
import org.torproject.metrics.collector.conf.Configuration;
import org.torproject.metrics.collector.conf.ConfigurationException;
import org.torproject.metrics.collector.conf.Key;
import org.torproject.metrics.collector.cron.CollecTorMain;
@ -82,7 +81,7 @@ public class CreateIndexJson extends CollecTorMain {
}
@Override
protected void startProcessing() throws ConfigurationException {
protected void startProcessing() {
try {
indexJsonFile = new File(config.getPath(Key.IndexPath).toFile(),
"index.json");

View File

@ -90,7 +90,7 @@ public class ArchiveWriter extends CollecTorMain {
private static final String MICRODESCS = "microdescs";
/** Initialize an archive writer with a given configuration. */
public ArchiveWriter(Configuration config) throws ConfigurationException {
public ArchiveWriter(Configuration config) {
super(config);
this.mapPathDescriptors.put("recent/relay-descriptors/votes",
RelayNetworkStatusVote.class);

View File

@ -37,8 +37,7 @@ public class LogFileMap
try {
Files.walkFileTree(startDir, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes att)
throws IOException {
public FileVisitResult visitFile(Path path, BasicFileAttributes att) {
Optional<LogMetadata> optionalMetadata = LogMetadata.create(path);
if (optionalMetadata.isPresent()) {
logFileMap.add(optionalMetadata.get());
@ -47,14 +46,12 @@ public class LogFileMap
}
@Override
public FileVisitResult visitFileFailed(Path path, IOException ex)
throws IOException {
public FileVisitResult visitFileFailed(Path path, IOException ex) {
return logIfError(path, ex);
}
@Override
public FileVisitResult postVisitDirectory(Path path, IOException ex)
throws IOException {
public FileVisitResult postVisitDirectory(Path path, IOException ex) {
return logIfError(path, ex);
}

View File

@ -18,7 +18,6 @@ import org.torproject.descriptor.log.InternalWebServerAccessLog;
import org.torproject.descriptor.log.WebServerAccessLogImpl;
import org.torproject.descriptor.log.WebServerAccessLogLine;
import org.torproject.metrics.collector.conf.Configuration;
import org.torproject.metrics.collector.conf.ConfigurationException;
import org.torproject.metrics.collector.conf.Key;
import org.torproject.metrics.collector.conf.SourceType;
import org.torproject.metrics.collector.cron.CollecTorMain;
@ -86,7 +85,7 @@ public class SanitizeWeblogs extends CollecTorMain {
}
@Override
protected void startProcessing() throws ConfigurationException {
protected void startProcessing() {
try {
Files.createDirectories(this.config.getPath(Key.OutputPath));
Files.createDirectories(this.config.getPath(Key.RecentPath));

View File

@ -55,7 +55,7 @@ public class MainTest {
}
@Test()
public void testInitializationNullArgs() throws Exception {
public void testInitializationNullArgs() {
File conf = new File(Main.CONF_FILE);
checkCleanEnv(conf);
Main.main(null);
@ -77,7 +77,7 @@ public class MainTest {
}
@Test()
public void testInitializationEmptyArgs() throws Exception {
public void testInitializationEmptyArgs() {
File conf = new File(Main.CONF_FILE);
checkCleanEnv(conf);
Main.main(new String[] { });
@ -86,7 +86,7 @@ public class MainTest {
}
@Test()
public void testInitializationTooManyArgs() throws Exception {
public void testInitializationTooManyArgs() {
File conf = new File(Main.CONF_FILE);
checkCleanEnv(conf);
Main.main(new String[] { "x", "y" });

View File

@ -10,7 +10,7 @@ import org.junit.Test;
public class BridgeDescriptorParserTest {
@Test(expected = IllegalArgumentException.class)
public void testNullArgForConstructor() throws Exception {
public void testNullArgForConstructor() {
new BridgeDescriptorParser(null);
}

View File

@ -63,7 +63,7 @@ class TarballTestBuilder {
/** Adds a new file to the tarball with given name, last-modified time, and
* descriptor builders to generate the file content. */
TarballTestBuilder add(String fileName, long modifiedMillis,
List<TestDescriptorBuilder> descriptorBuilders) throws IOException {
List<TestDescriptorBuilder> descriptorBuilders) {
TarballFile file = new TarballFile();
file.modifiedMillis = modifiedMillis;
file.descriptorBuilders = descriptorBuilders;

View File

@ -37,14 +37,14 @@ public class ConfigurationTest {
public TemporaryFolder tmpf = new TemporaryFolder();
@Test()
public void testKeyCount() throws Exception {
public void testKeyCount() {
assertEquals("The number of properties keys in enum Key changed."
+ "\n This test class should be adapted.",
53, Key.values().length);
}
@Test()
public void testConfiguration() throws Exception {
public void testConfiguration() {
Configuration conf = new Configuration();
String val = "xyz";
conf.setProperty(Key.OutputPath.name(), val);

View File

@ -4,7 +4,6 @@
package org.torproject.metrics.collector.cron;
import org.torproject.metrics.collector.conf.Configuration;
import org.torproject.metrics.collector.conf.ConfigurationException;
import java.util.concurrent.atomic.AtomicInteger;
@ -17,7 +16,7 @@ public class Broken extends CollecTorMain {
}
@Override
public void startProcessing() throws ConfigurationException {
public void startProcessing() {
count.getAndIncrement();
try {
Thread.sleep(10);

View File

@ -1,7 +1,6 @@
package org.torproject.metrics.collector.cron;
import org.torproject.metrics.collector.conf.Configuration;
import org.torproject.metrics.collector.conf.ConfigurationException;
import java.util.concurrent.atomic.AtomicInteger;
@ -14,7 +13,7 @@ public class Counter extends CollecTorMain {
}
@Override
public void startProcessing() throws ConfigurationException {
public void startProcessing() {
count.getAndIncrement();
}

View File

@ -1,7 +1,6 @@
package org.torproject.metrics.collector.cron;
import org.torproject.metrics.collector.conf.Configuration;
import org.torproject.metrics.collector.conf.ConfigurationException;
public class Dummy extends CollecTorMain {
@ -10,7 +9,7 @@ public class Dummy extends CollecTorMain {
}
@Override
public void startProcessing() throws ConfigurationException {
public void startProcessing() {
// dummy doesn't do anything.
}

View File

@ -4,7 +4,6 @@
package org.torproject.metrics.collector.sync;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
@ -20,8 +19,7 @@ public class FileCollector extends SimpleFileVisitor<Path> {
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
throws IOException {
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
this.list.add(file.toFile());
return FileVisitResult.CONTINUE;
}

View File

@ -355,7 +355,7 @@ public class SyncPersistenceTest {
.getClassLoader().getResource(filename).toURI())).toPath());
}
private String stringFromResource() throws Exception {
private String stringFromResource() {
BufferedReader br = new BufferedReader(new InputStreamReader(getClass()
.getClassLoader().getResourceAsStream(filename)));
return br.lines().collect(Collectors.joining("\n", "", "\n"));
@ -366,7 +366,7 @@ public class SyncPersistenceTest {
.collect(Collectors.joining("\n", "", "\n"));
}
private List<String> linesFromResource(String filename) throws Exception {
private List<String> linesFromResource(String filename) {
BufferedReader br = new BufferedReader(new InputStreamReader(getClass()
.getClassLoader().getResourceAsStream(filename)));
return br.lines().collect(Collectors.toList());

View File

@ -67,7 +67,7 @@ public class LogMetadataTest {
}
@Test
public void testCreate() throws Exception {
public void testCreate() {
Optional<LogMetadata> element = LogMetadata.create(this.path);
assertEquals(this.failureMessage, this.valid, element.isPresent());
if (!this.valid) {