sarvekshayr commented on code in PR #9316:
URL: https://github.com/apache/ozone/pull/9316#discussion_r2536579034
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/stream/DirstreamClientHandler.java:
##########
@@ -80,7 +80,18 @@ public void doRead(ChannelHandlerContext ctx, ByteBuf buffer)
name.release();
buffer.skipBytes(1);
String[] parts = currentFileName.split(" ", 2);
- remaining = Long.parseLong(parts[0]);
+ if (parts.length < 2 || parts[1].isEmpty()) {
+ throw new IllegalArgumentException("Invalid file name format: " +
currentFileName + ". "
+ + "Expected format: <size> <filename> where <size> is a number
and <filename> "
+ + "is a string separated by a single space. Example: '1024
myfile.txt'");
+ }
+ try {
+ remaining = Long.parseLong(parts[0]);
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException("Invalid file name format: " +
currentFileName + ". "
+ + "Expected format: <size> <filename> where <size> is a number
and <filename> "
+ + "is a string separated by a single space. Example: '1024
myfile.txt'", e);
+ }
Review Comment:
Let's create a constant for the error message and use it in both places to
keep it clean.
```
private static final String INVALID_FORMAT_MESSAGE =
"Expected format: <size> <filename> where <size> is a number and
<filename> " +
"is a string separated by a single space. Example: '1024 myfile.txt'";
```
```suggestion
if (parts.length < 2 || parts[1].isEmpty()) {
throw new IllegalArgumentException(
"Invalid file name format: " + currentFileName + ". " +
INVALID_FORMAT_MESSAGE);
}
try {
remaining = Long.parseLong(parts[0]);
} catch (NumberFormatException e) {
throw new IllegalArgumentException(
"Invalid file name format: " + currentFileName + ". " +
INVALID_FORMAT_MESSAGE, e);
}
```
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]