gnodet-bot commented on code in PR #27926:
URL: https://github.com/apache/camel/pull/27926#discussion_r4289663049
##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/Dirty.java:
##########
@@ -76,4 +75,28 @@ public Integer doCall() throws Exception {
return 0;
}
+ /**
+ * The pid a file in the Camel directory belongs to, such as 123 for
{@code 123-status.json}, {@code 123} and the
+ * infra service file {@code infra-kafka-123.json}, or <tt>null</tt> for a
file that belongs to no process.
+ */
+ static Long pidOf(String fileName) {
+ if (fileName.startsWith("infra-") && fileName.lastIndexOf('-') > 5) {
+ // infra-<service>-<pid>.json and .log
+ fileName = fileName.substring(fileName.lastIndexOf('-') + 1);
+ }
+ int end = 0;
+ while (end < fileName.length() &&
Character.isDigit(fileName.charAt(end))) {
+ end++;
+ }
+ boolean separated = end == fileName.length() || fileName.charAt(end)
== '-' || fileName.charAt(end) == '.';
+ if (end == 0 || !separated) {
+ return null;
+ }
+ try {
+ return Long.parseLong(fileName.substring(0, end));
+ } catch (NumberFormatException e) {
+ return null;
+ }
Review Comment:
💡 **Minor:** A filename consisting entirely of digits longer than
`Long.MAX_VALUE` (e.g. `"99999999999999999999999"`) passes the `separated`
check (`end == fileName.length()`) and reaches `Long.parseLong`, which throws
`NumberFormatException` — caught here and returned as `null`, so the behaviour
is safe. Worth noting in a comment that the catch is intentional for oversized
digit strings, not just a defensive fallback for an "impossible" case. Fine
as-is in practice since real PIDs never exceed `Long.MAX_VALUE`.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]