[
https://issues.apache.org/jira/browse/NIFI-15316?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18047356#comment-18047356
]
Swati Gupta commented on NIFI-15316:
------------------------------------
Hi,
I've analyzed this issue and reproduced the logic error in
{{{}GetFile.java{}}}. Because the slash is appended before the check, the
{{isEmpty()}} condition is indeed unreachable dead code.
I have a local development environment set up with Java 21 and would like to
work on a fix for this.
Could you please assign this issue to me?
> [GetFile] Dead code in onTrigger - isEmpty() check unreachable after string
> concatenation
> -----------------------------------------------------------------------------------------
>
> Key: NIFI-15316
> URL: https://issues.apache.org/jira/browse/NIFI-15316
> Project: Apache NiFi
> Issue Type: Bug
> Components: Core Framework
> Affects Versions: 2.6.0
> Environment: Platform irrelevant (code logic issue)
> Reporter: Kim Seung Ho
> Priority: Trivial
> Fix For: 2.6.0
>
>
> In GetFile.java, the isEmpty() check at line 423-425 is dead code.
> {code:java}
> // Before modification (current code)
> String relativePathString = relativePath.toString() + "/";
> if (relativePathString.isEmpty()) {
> relativePathString = "./";
> } {code}
> The variable `relativePathString` is assigned with `relativePath.toString() +
> "/"`
> which always contains at least "/" character, making the isEmpty() condition
> always false.
> The original intent was likely to check if relativePath is empty (when file
> is
> directly under the input directory), but the "/" is appended before the check.
> Fix: Check isEmpty() on relativePath.toString() before appending "/".
> {code:java}
> // After modification
> String relativePathString = relativePath.toString();
> if (relativePathString.isEmpty()) {
> relativePathString = "./";
> } else {
> relativePathString = relativePathString + "/";
> } {code}
> or, simply
> {code:java}
> // After modification
> String relativePathString = relativePath.toString();
> relativePathString = relativePathString.isEmpty() ? "./" : relativePathString
> + "/"; {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)