Skip to content

Commit

Permalink
Simplify flow
Browse files Browse the repository at this point in the history
Remove trailing whitespace
Use final
Use method references
Don't create extra String objects
Remove unused imports
space after catch
  • Loading branch information
garydgregory committed Oct 22, 2023
1 parent f4beb5d commit 6fb582d
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,8 @@ private String handleURISpecialCharacters(String uri) {
uri = UriParser.decode(uri);

return UriParser.encode(uri, RESERVED_URI_CHARS);
} catch (final FileSystemException e) {
} catch (final FileSystemException ignore) { // NOPMD
// Default to base URI value?
return uri;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void close() {
}

// Close all components
Stream.of(toclose).filter(component -> component instanceof VfsComponent)
Stream.of(toclose).filter(VfsComponent.class::isInstance)
.forEach(component -> ((VfsComponent) component).close());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public File[] getIdentities(final FileSystemOptions options) {
public IdentityInfo[] getIdentityInfo(final FileSystemOptions options) {
final IdentityProvider[] infos = getIdentityProvider(options);
if (infos != null) {
return Stream.of(infos).filter(info -> info instanceof IdentityInfo).map(info -> (IdentityInfo) info).toArray(IdentityInfo[]::new);
return Stream.of(infos).filter(IdentityInfo.class::isInstance).map(info -> (IdentityInfo) info).toArray(IdentityInfo[]::new);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void testGetStringCharset() throws Exception {
assertEquals(FileType.FILE, file.getType());
assertTrue(file.isFile());

assertEquals(FILE1_CONTENT, new String(file.getContent().getString(StandardCharsets.UTF_8)));
assertEquals(FILE1_CONTENT, file.getContent().getString(StandardCharsets.UTF_8));
}
}

Expand All @@ -171,7 +171,7 @@ public void testGetStringString() throws Exception {
assertEquals(FileType.FILE, file.getType());
assertTrue(file.isFile());

assertEquals(FILE1_CONTENT, new String(file.getContent().getString(StandardCharsets.UTF_8.name())));
assertEquals(FILE1_CONTENT, file.getContent().getString(StandardCharsets.UTF_8.name()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Iterator;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -83,11 +81,10 @@ public void testIterator() throws FileSystemException {
assertEquals(expectedFile, actualFile);
i++;
}
final Iterator<FileObject> iter = baseFolder.iterator();
i = 0;
while (iter.hasNext()) {
for (FileObject element : baseFolder) {
final FileObject expectedFile = findFiles[i];
assertEquals(expectedFile, iter.next());
assertEquals(expectedFile, element);
i++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class FileObjectContentOutputStreamCloseTest {

@Test
public void test() throws IOException {
Path tempFilePath = Files.createTempFile("org.apache.commons.vfs2", ".txt");
final Path tempFilePath = Files.createTempFile("org.apache.commons.vfs2", ".txt");
try (@SuppressWarnings("resource") // VFS.getManager() is a constant.
FileObject fileObject = VFS.getManager().resolveFile(tempFilePath.toUri());
final FileContent content = fileObject.getContent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private static void assertSftpOptionsEquals(final File privKey, final File pubKe
}

private static void assertSftpOptionsNotEquals(final File privKey1, final File pubKey1, final byte[] passphrase1,
File privKey2, File pubKey2, byte[] passphrase2) {
final File privKey2, final File pubKey2, final byte[] passphrase2) {
final SftpFileSystemConfigBuilder builder = SftpFileSystemConfigBuilder.getInstance();

final FileSystemOptions expected = new FileSystemOptions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class VfsClassLoaderTests extends AbstractProviderTestCase {

private class LoadClass implements Runnable {
private final VFSClassLoader loader;
public LoadClass(VFSClassLoader loader) {
public LoadClass(final VFSClassLoader loader) {
this.loader = loader;
}

Expand Down Expand Up @@ -242,29 +242,20 @@ public void testThreadSafety() throws Exception {
final int THREADS = 40;
final BlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<>(THREADS * 2);
final List<Throwable> exceptions = new ArrayList<>();
final Thread.UncaughtExceptionHandler handler = new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
synchronized (exceptions) {
exceptions.add(e);
}
final Thread.UncaughtExceptionHandler handler = (t, e) -> {
synchronized (exceptions) {
exceptions.add(e);
}
};
final ThreadFactory factory = new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread thread = new Thread(r, "VfsClassLoaderTests.testThreadSafety");
thread.setUncaughtExceptionHandler(handler);
return thread;
}
final ThreadFactory factory = r -> {
final Thread thread = new Thread(r, "VfsClassLoaderTests.testThreadSafety");
thread.setUncaughtExceptionHandler(handler);
return thread;
};
final Queue<Runnable> rejections = new LinkedList<>();
final RejectedExecutionHandler rejectionHandler = new RejectedExecutionHandler() {
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
synchronized (rejections) {
rejections.add(r);
}
final RejectedExecutionHandler rejectionHandler = (r, executor) -> {
synchronized (rejections) {
rejections.add(r);
}
};
final ThreadPoolExecutor executor = new ThreadPoolExecutor(THREADS, THREADS, 0, TimeUnit.SECONDS, workQueue, factory, rejectionHandler);
Expand All @@ -288,10 +279,10 @@ public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
executor.awaitTermination(30, TimeUnit.SECONDS);
assertEquals(THREADS, executor.getCompletedTaskCount());
if (!exceptions.isEmpty()) {
StringBuilder exceptionMsg = new StringBuilder();
StringBuilderWriter writer = new StringBuilderWriter(exceptionMsg);
PrintWriter pWriter = new PrintWriter(writer);
for (Throwable t : exceptions) {
final StringBuilder exceptionMsg = new StringBuilder();
final StringBuilderWriter writer = new StringBuilderWriter(exceptionMsg);
final PrintWriter pWriter = new PrintWriter(writer);
for (final Throwable t : exceptions) {
pWriter.write(t.getMessage());
pWriter.write('\n');
t.printStackTrace(pWriter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public void testNotFoundOperation() throws FileSystemException {
final FileOperations ops = fo.getFileOperations();
assertNotNull(ops);

FileSystemException thrown = assertThrows(FileSystemException.class, () -> ops.getOperation(VcsLog.class));
final FileSystemException thrown = assertThrows(FileSystemException.class, () -> ops.getOperation(VcsLog.class));
assertEquals("vfs.operation/operation-not-supported.error", thrown.getCode());
assertSame(32, myop.ops); // getOperation was called
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void testTypeOfNormalizedPath() {
assertEquals(FileType.FILE, UriParser.normalisePath(new StringBuilder("./Sub Folder/./File.")));
assertEquals(FileType.FILE, UriParser.normalisePath(new StringBuilder("./Sub Folder/./File..")));

} catch(FileSystemException e) {
} catch (FileSystemException e) {
fail(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
abstract class AbstractFtpsProviderTestCase extends AbstractProviderTestConfig {

static final class FtpProviderTestSuite extends ProviderTestSuite {

private final boolean implicit;

public FtpProviderTestSuite(final AbstractFtpsProviderTestCase providerConfig) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

/**
* See https://issues.apache.org/jira/browse/FTPSERVER-491.
*
*
* See https://issues.apache.org/jira/browse/FTPSERVER-506.
*/
public class NoProtocolSslConfigurationProxy implements SslConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class GzipTest {
public void testCreateGzipFileSystem() throws IOException {
final File gzFile = new File("src/test/resources/test-data/好.txt.gz");
@SuppressWarnings("resource") // global
FileSystemManager manager = VFS.getManager();
final FileSystemManager manager = VFS.getManager();

try (FileObject localFileObject = manager.resolveFile(gzFile.getAbsolutePath());
FileObject gzFileObjectDir = manager.createFileSystem(localFileObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ protected static String getSystemTestUriOverride() {
* @throws FtpException
* @throws IOException
*/
private static void setUpClass(final boolean isExecChannelClosed, SessionFactory sessionFactory) throws IOException {
private static void setUpClass(final boolean isExecChannelClosed, final SessionFactory sessionFactory) throws IOException {
if (server != null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ private NHttpFileServer start() throws KeyManagementException, UnrecoverableKeyE
// @formatter:on

server = bootstrap
.setExceptionCallback(e -> e.printStackTrace())
.setExceptionCallback(Exception::printStackTrace)
.setIOReactorConfig(config)
.register("*", new HttpFileHandler(docRoot)).create();

Expand Down

0 comments on commit 6fb582d

Please sign in to comment.