This repository has been archived by the owner on Feb 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 738
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add parameter guards to all public methods.
- Loading branch information
Showing
13 changed files
with
250 additions
and
7 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
wrappers/java/src/main/java/org/hyperledger/indy/sdk/ParamGuard.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.hyperledger.indy.sdk; | ||
|
||
public class ParamGuard { | ||
|
||
public static void notNull(Object param, String paramName) { | ||
if(param == null) | ||
throw new IllegalArgumentException("A value must be provided for the '" + paramName + "' parameter."); | ||
} | ||
|
||
public static void notNullOrWhiteSpace(String param, String paramName) { | ||
if(StringUtils.isNullOrWhiteSpace(param)) | ||
throw new IllegalArgumentException("A non-empty string must be provided for the '" + paramName + "' parameter."); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
wrappers/java/src/main/java/org/hyperledger/indy/sdk/StringUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.hyperledger.indy.sdk; | ||
|
||
public class StringUtils { | ||
|
||
public static boolean isNullOrWhiteSpace(String s) { | ||
if (s == null) | ||
return true; | ||
|
||
for (int i = 0; i < s.length(); i++) { | ||
if (!Character.isWhitespace(s.charAt(i))) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.