Skip to content

Commit

Permalink
Check matcher to avoid IllegalStateException
Browse files Browse the repository at this point in the history
  • Loading branch information
ar committed Jan 20, 2025
1 parent 58897ac commit 6bded12
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions jpos/src/main/java/org/jpos/util/PGPHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,16 @@ public class PGPHelper {
String nodeString = Environment.get("${q2.node:1}");
Pattern pattern = Pattern.compile("\\d+");

node = (nodeString == null || nodeString.isEmpty())
? 1
: (pattern.matcher(nodeString).find()
? Integer.parseInt(pattern.matcher(nodeString).group())
: 1);
try {
Matcher matcher = pattern.matcher(nodeString);
node = (nodeString == null || nodeString.isEmpty())
? 1 // Default value if nodeString is null or empty
: (matcher.find()
? Integer.parseInt(matcher.group()) // Use matched digits if found
: 1); // Default value if no match is found
} catch (Throwable e) {
node = 0; // Fallback to default value in case of any exception
}
}

private static boolean verifySignature(InputStream in, PGPPublicKey pk) throws IOException, PGPException {
Expand Down

0 comments on commit 6bded12

Please sign in to comment.