You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2020/12/11 23:29:14 UTC

[GitHub] [commons-codec] garydgregory commented on a change in pull request #67: [CODEC-295] - Minor improvement

garydgregory commented on a change in pull request #67:
URL: https://github.com/apache/commons-codec/pull/67#discussion_r541408191



##########
File path: src/main/java/org/apache/commons/codec/cli/Digest.java
##########
@@ -61,16 +61,17 @@ private Digest(final String[] args) {
         if (args == null) {
             throw new IllegalArgumentException("args");
         }
-        if (args.length == 0) {
+        final int argsLength = args.length;
+        if (argsLength == 0) {
             throw new IllegalArgumentException(
                     String.format("Usage: java %s [algorithm] [FILE|DIRECTORY|string] ...", Digest.class.getName()));
         }
         this.args = args;
         algorithm = args[0];
-        if (args.length <= 1) {
+        if (argsLength <= 1) {
             inputs = null;
         } else {
-            inputs = new String[args.length -1];
+            inputs = new String[argsLength -1];

Review comment:
       Formatting.

##########
File path: src/main/java/org/apache/commons/codec/language/bm/Rule.java
##########
@@ -507,7 +516,7 @@ public boolean isMatch(final CharSequence input) {
                         return input.equals(content);
                     }
                 };
-            } else if ((startsWith || endsWith) && content.length() == 0) {
+            } else if ((startsWith || endsWith) && contentLength == 0) {

Review comment:
       See above.

##########
File path: src/test/java/org/apache/commons/codec/cli/DigestTest.java
##########
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.codec.cli;
+
+import org.junit.Test;
+
+import java.io.IOException;
+
+
+/**
+ * Tests {@link Digest}.
+ *
+ * @since 1.17
+ */
+public class DigestTest{
+
+    /**
+     * Tests if empty arguments are handled correctly.
+     *
+     * @throws IllegalArgumentException for some failure scenarios.
+     */
+    @Test(expected = IllegalArgumentException.class)

Review comment:
       Do we need a local var?

##########
File path: src/main/java/org/apache/commons/codec/binary/Hex.java
##########
@@ -168,7 +168,7 @@ public static int decodeHex(final char[] data, final byte[] out, final int outOf
     protected static char[] encodeHex(final byte[] data, final char[] toDigits) {
         final int l = data.length;
         final char[] out = new char[l << 1];
-        encodeHex(data, 0, data.length, toDigits, out, 0);
+        encodeHex(data, 0, l, toDigits, out, 0);

Review comment:
       No mystery names please, especially "l" which can look just like a "1" depending on your font!

##########
File path: src/main/java/org/apache/commons/codec/language/bm/Rule.java
##########
@@ -488,11 +496,12 @@ private static RPattern pattern(final String regex) {
         final boolean endsWith = regex.endsWith("$");
         final String content = regex.substring(startsWith ? 1 : 0, endsWith ? regex.length() - 1 : regex.length());
         final boolean boxes = content.contains("[");
+        final int contentLength = content.length();
 
         if (!boxes) {
             if (startsWith && endsWith) {
                 // exact match
-                if (content.length() == 0) {
+                if (contentLength == 0) {

Review comment:
       Just use `String#isEmpty()` for 0-length checks on Strings.
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org