Merge "Moved null ref check to line before dereferencing"
authorJonathan Gathman <jonathan.gathman@att.com>
Wed, 3 Jul 2019 14:10:52 +0000 (14:10 +0000)
committerGerrit Code Review <gerrit@onap.org>
Wed, 3 Jul 2019 14:10:52 +0000 (14:10 +0000)
cadi/aaf/src/main/java/org/onap/aaf/cadi/oauth/TokenClientFactory.java

index b3cf266..14cf0f6 100644 (file)
@@ -152,15 +152,17 @@ public class TokenClientFactory extends Persist<Token,TimedToken> {
             }
             sb.append('_');
             sb.append(tokenSource);
-            byte[] tohash=scope.getBytes();
-            if (hash!=null && hash.length>0) {
-                byte temp[] = new byte[hash.length+tohash.length];
-                System.arraycopy(tohash, 0, temp, 0, tohash.length);
-                System.arraycopy(hash, 0, temp, tohash.length, hash.length);
-                tohash = temp;
-            }
-            if (scope!=null && scope.length()>0) {
-                sb.append(Hash.toHexNo0x(Hash.hashSHA256(tohash)));
+            if (scope!=null) {
+                byte[] tohash=scope.getBytes();
+                if (hash!=null && hash.length>0) {
+                    byte temp[] = new byte[hash.length+tohash.length];
+                    System.arraycopy(tohash, 0, temp, 0, tohash.length);
+                    System.arraycopy(hash, 0, temp, tohash.length, hash.length);
+                    tohash = temp;
+                }
+                if (scope.length()>0) {
+                    sb.append(Hash.toHexNo0x(Hash.hashSHA256(tohash)));
+                }
             }
             return sb.toString();
         } catch (NoSuchAlgorithmException e) {