commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject svn commit: r1845521 - in /commons/proper/vfs/trunk: commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/ commons-vfs2/src/main/java/org/apache/commons/vfs2/ commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/ commons-vfs2/src/main...
Date Thu, 01 Nov 2018 23:11:47 GMT
Author: ecki
Date: Thu Nov  1 23:11:46 2018
New Revision: 1845521

URL: http://svn.apache.org/viewvc?rev=1845521&view=rev
Log:
[VFS-678] fix various LGTM.com warnings.

Modified:
    commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/Shell.java
    commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileName.java
    commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/UserAuthenticationData.java
    commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/DefaultFileMonitor.java
    commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/compressed/CompressedFileFileProvider.java
    commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/tasks/ShowFileTask.java
    commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/DefaultCryptor.java
    commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/MonitorInputStream.java
    commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/test/AbstractProviderTestCase.java
    commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/util/EncryptDecryptTest.java
    commons/proper/vfs/trunk/src/changes/changes.xml

Modified: commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/Shell.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/Shell.java?rev=1845521&r1=1845520&r2=1845521&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/Shell.java
(original)
+++ commons/proper/vfs/trunk/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/Shell.java
Thu Nov  1 23:11:46 2018
@@ -23,6 +23,7 @@ import java.io.InputStreamReader;
 import java.nio.charset.Charset;
 import java.text.DateFormat;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Date;
 import java.util.List;
@@ -154,7 +155,7 @@ public final class Shell {
         }
         final FileOperationProvider[] ops = mgr.getOperationProviders(scheme);
         if (ops != null && ops.length > 0) {
-            System.out.println("  operations: " + ops);
+            System.out.println("  operations: " + Arrays.asList(ops));
         }
     }
 

Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileName.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileName.java?rev=1845521&r1=1845520&r2=1845521&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileName.java
(original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileName.java
Thu Nov  1 23:11:46 2018
@@ -127,28 +127,6 @@ public interface FileName extends Compar
     FileName getParent();
 
     /**
-     * Resolves a name, relative to this file name. Equivalent to calling
-     * {@code resolveName( path, NameScope.FILE_SYSTEM )}.
-     *
-     * @param name The name to resolve.
-     * @return A {@link FileName} object representing the resolved file name.
-     * @throws FileSystemException If the name is invalid.
-     */
-    // FileName resolveName(String name) throws FileSystemException;
-
-    /**
-     * Resolves a name, relative to this file name. Refer to {@link NameScope} for a description
of how names are
-     * resolved.
-     *
-     * @param name The name to resolve.
-     * @param scope The scope to use when resolving the name.
-     * @return A {@link FileName} object representing the resolved file name.
-     * @throws FileSystemException If the name is invalid.
-     */
-    // FileName resolveName(String name, NameScope scope)
-    // throws FileSystemException;
-
-    /**
      * Converts a file name to a relative name, relative to this file name.
      *
      * @param name The name to convert to a relative path.

Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/UserAuthenticationData.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/UserAuthenticationData.java?rev=1845521&r1=1845520&r2=1845521&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/UserAuthenticationData.java
(original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/UserAuthenticationData.java
Thu Nov  1 23:11:46 2018
@@ -129,7 +129,7 @@ public class UserAuthenticationData {
         final Iterator<char[]> iterAuthenticationData = authenticationData.values().iterator();
         while (iterAuthenticationData.hasNext()) {
             final char[] data = iterAuthenticationData.next();
-            if (data == null || data.length < 0) {
+            if (data == null) {
                 continue;
             }
 

Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/DefaultFileMonitor.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/DefaultFileMonitor.java?rev=1845521&r1=1845520&r2=1845521&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/DefaultFileMonitor.java
(original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/DefaultFileMonitor.java
Thu Nov  1 23:11:46 2018
@@ -487,11 +487,11 @@ public class DefaultFileMonitor implemen
                     } else {
                         // First set of children - Break out the cigars
                         if (newChildren.length > 0) {
-                            this.children = new HashMap<>();
-                        }
-                        for (final FileObject element : newChildren) {
-                            this.children.put(element.getName(), new Object()); // null?
-                            this.fireAllCreate(element);
+                        	this.children = new HashMap<>();
+                        	for (final FileObject element : newChildren) {
+                        		this.children.put(element.getName(), new Object()); // null?
+                        		this.fireAllCreate(element);
+                        	}
                         }
                     }
                 }

Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/compressed/CompressedFileFileProvider.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/compressed/CompressedFileFileProvider.java?rev=1845521&r1=1845520&r2=1845521&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/compressed/CompressedFileFileProvider.java
(original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/compressed/CompressedFileFileProvider.java
Thu Nov  1 23:11:46 2018
@@ -37,15 +37,6 @@ public abstract class CompressedFileFile
     }
 
     /**
-     * Parses an absolute URI.
-     *
-     * @param uri The URI to parse.
-     */
-    /*
-     * public FileName parseUri(final String uri) throws FileSystemException { return ZipFileName.parseUri(uri);
}
-     */
-
-    /**
      * Creates a layered file system. This method is called if the file system is not cached.
      *
      * @param scheme The URI scheme.

Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/tasks/ShowFileTask.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/tasks/ShowFileTask.java?rev=1845521&r1=1845520&r2=1845521&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/tasks/ShowFileTask.java
(original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/tasks/ShowFileTask.java
Thu Nov  1 23:11:46 2018
@@ -121,9 +121,10 @@ public class ShowFileTask extends VfsTas
      * Writes the content of the file to Ant log.
      */
     private void logContent(final FileObject file, final String prefix) throws Exception
{
-        final InputStream instr = file.getContent().getInputStream();
-        try {
-            final BufferedReader reader = new BufferedReader(new InputStreamReader(instr));
+        try (
+            final InputStream instr = file.getContent().getInputStream();
+            final BufferedReader reader = new BufferedReader(new InputStreamReader(instr));
) 
+        {
             while (true) {
                 final String line = reader.readLine();
                 if (line == null) {
@@ -131,8 +132,6 @@ public class ShowFileTask extends VfsTas
                 }
                 log(prefix + line);
             }
-        } finally {
-            instr.close();
         }
     }
 }

Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/DefaultCryptor.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/DefaultCryptor.java?rev=1845521&r1=1845520&r2=1845521&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/DefaultCryptor.java
(original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/DefaultCryptor.java
Thu Nov  1 23:11:46 2018
@@ -96,24 +96,28 @@ public class DefaultCryptor implements C
         return builder.toString();
     }
 
-    /** Decodes Hey-Bytes. */
+    /** Decodes Hex-Bytes. */
     private byte[] decode(final String str) {
-        final int length = str.length() / 2;
-        final byte[] decoded = new byte[length];
         final char[] chars = str.toCharArray();
+        final int length = chars.length / 2;
+        final byte[] decoded = new byte[length];
+        if (length * 2 != chars.length)
+        {
+        	throw new IllegalArgumentException("The given string must have even number of hex
chars.");
+        }
         int index = 0;
-        for (int i = 0; i < chars.length; ++i) {
-            final int id1 = indexOf(HEX_CHARS, chars[i]);
-            if (id1 == -1) {
+        for (int i = 0; i < length; i++) {
+            final int id1 = indexOf(HEX_CHARS, chars[index++]);
+            if (id1 == INDEX_NOT_FOUND) {
                 throw new IllegalArgumentException(
-                        "Character " + chars[i] + " at position " + i + " is not a valid
hexidecimal character");
+                        "Character " + chars[index-1] + " at position " + (index-1) + " is
not a valid hexidecimal character");
             }
-            final int id2 = indexOf(HEX_CHARS, chars[++i]);
-            if (id2 == -1) {
+            final int id2 = indexOf(HEX_CHARS, chars[index++]);
+            if (id2 == INDEX_NOT_FOUND) {
                 throw new IllegalArgumentException(
-                        "Character " + chars[i] + " at position " + i + " is not a valid
hexidecimal character");
+                        "Character " + chars[index-1] + " at position " + (index-1) + " is
not a valid hexidecimal character");
             }
-            decoded[index++] = (byte) ((id1 << BITS_IN_HALF_BYTE) | id2);
+            decoded[i] = (byte) ((id1 << BITS_IN_HALF_BYTE) | id2);
         }
         return decoded;
     }

Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/MonitorInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/MonitorInputStream.java?rev=1845521&r1=1845520&r2=1845521&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/MonitorInputStream.java
(original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/MonitorInputStream.java
Thu Nov  1 23:11:46 2018
@@ -57,7 +57,7 @@ public class MonitorInputStream extends
      * @throws IOException if an error occurs.
      */
     @Override
-    public int read() throws IOException {
+    public synchronized int read() throws IOException { // lgtm [java/non-sync-override]
         if (finished.get()) {
             return EOF_CHAR;
         }
@@ -83,14 +83,14 @@ public class MonitorInputStream extends
      * @throws IOException if an error occurs.
      */
     @Override
-    public int read(final byte[] buffer, final int offset, final int length) throws IOException
{
+    public int read(final byte[] buffer, final int offset, final int length) throws IOException
{ // lgtm [java/non-sync-override]
         if (finished.get()) {
             return EOF_CHAR;
         }
 
         final int nread = super.read(buffer, offset, length);
         if (nread != EOF_CHAR) {
-            atomicCount.addAndGet(nread);
+        	atomicCount.addAndGet(nread);
             return nread;
         }
         return EOF_CHAR;

Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/test/AbstractProviderTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/test/AbstractProviderTestCase.java?rev=1845521&r1=1845520&r2=1845521&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/test/AbstractProviderTestCase.java
(original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/test/AbstractProviderTestCase.java
Thu Nov  1 23:11:46 2018
@@ -75,6 +75,11 @@ public abstract class AbstractProviderTe
         this.baseFolder = baseFolder;
         this.readFolder = readFolder;
         this.writeFolder = writeFolder;
+        assertNotNull("setConfig manager", manager);
+        assertNotNull("setConfig providerConfig", providerConfig);
+        assertNotNull("setConfig baseFolder", baseFolder);
+        assertNotNull("setConfig readFolder", readFolder);
+        assertNotNull("setConfig writeFolder", writeFolder);
     }
 
     /**
@@ -172,7 +177,7 @@ public abstract class AbstractProviderTe
         if (caps != null) {
             for (final Capability cap2 : caps) {
                 final Capability cap = cap2;
-                final FileSystem fs = readFolder.getFileSystem();
+                final FileSystem fs = getFileSystem();
                 if (!fs.hasCapability(cap)) {
                     // String name = fs.getClass().getName();
                     // int index = name.lastIndexOf('.');

Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/util/EncryptDecryptTest.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/util/EncryptDecryptTest.java?rev=1845521&r1=1845520&r2=1845521&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/util/EncryptDecryptTest.java
(original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/util/EncryptDecryptTest.java
Thu Nov  1 23:11:46 2018
@@ -35,6 +35,13 @@ public class EncryptDecryptTest {
 
         final String decrypted = cryptor.decrypt(encrypted);
         assertEquals(source, decrypted);
-
+    }
+    
+    @Test(expected=IllegalArgumentException.class)
+    public void testInvalidDecrypt() throws Exception {
+    	// provider.HostFileNameParser.extractToPath(String, StringBuilder) catches `Exception`
+    	final String broken = "91458";
+        final Cryptor cryptor = CryptorFactory.getCryptor();
+        /* ignored */ cryptor.decrypt(broken);
     }
 }

Modified: commons/proper/vfs/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/src/changes/changes.xml?rev=1845521&r1=1845520&r2=1845521&view=diff
==============================================================================
--- commons/proper/vfs/trunk/src/changes/changes.xml (original)
+++ commons/proper/vfs/trunk/src/changes/changes.xml Thu Nov  1 23:11:46 2018
@@ -50,6 +50,9 @@ The <action> type attribute can be add,u
 <!--        [Local] Need an easy way to convert from a FileObject to a File. -->
 <!--       </action> -->
 <!-- START Might need to be moved to the next version -->
+      <action issue="VFS-678" dev="ecki" type="fix">
+        Fix various LGTM.com code review warnings.
+      </action>
       <action issue="VFS-652" dev="ecki" type="fix">
         PatternFileSelector documentation to describe actual matching against getPath().
       </action>



Mime
View raw message