exceptionfactory commented on code in PR #11245:
URL: https://github.com/apache/nifi/pull/11245#discussion_r3253192050


##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/TailFile.java:
##########
@@ -415,6 +415,7 @@ public void recoverState(final ProcessContext context) 
throws IOException {
 
     private void initStates(final List<String> filesToTail, final Map<String, 
String> statesMap, final boolean isCleared) {
         int fileIndex = 0;
+        final Set<String> filesToTailSet = new HashSet<>(filesToTail);

Review Comment:
   What is the reason for creating this wrapping Set?



##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/TailFile.java:
##########
@@ -427,9 +428,19 @@ private void initStates(final List<String> filesToTail, 
final Map<String, String
                 for (Entry<String, String> entry : statesMap.entrySet()) {
                     final String key = entry.getKey();
                     final String value = entry.getValue();
-                    if (key.endsWith(TailFileState.StateKeys.FILENAME) && 
filesToTail.contains(value)) {
-                        int index = Integer.parseInt(key.split("\\.")[1]);
-                        states.put(value, new TailFileObject(index, statesMap, 
preAllocatedBufferSize));
+                    if (key.endsWith(TailFileState.StateKeys.FILENAME) && 
filesToTailSet.contains(value)) {
+                        final int index;
+                        try {
+                            index = Integer.parseInt(key.split("\\.")[1]);
+                        } catch (final RuntimeException e) {
+                            getLogger().warn("Ignoring malformed TailFile 
state key {}", key, e);
+                            continue;
+                        }
+                        try {
+                            states.put(value, new TailFileObject(index, 
statesMap, preAllocatedBufferSize));
+                        } catch (final RuntimeException e) {
+                            getLogger().warn("Ignoring malformed TailFile 
state for {}", value, e);
+                        }

Review Comment:
   This catch also seems too broad and not necessary.



##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/TailFile.java:
##########
@@ -427,9 +428,19 @@ private void initStates(final List<String> filesToTail, 
final Map<String, String
                 for (Entry<String, String> entry : statesMap.entrySet()) {
                     final String key = entry.getKey();
                     final String value = entry.getValue();
-                    if (key.endsWith(TailFileState.StateKeys.FILENAME) && 
filesToTail.contains(value)) {
-                        int index = Integer.parseInt(key.split("\\.")[1]);
-                        states.put(value, new TailFileObject(index, statesMap, 
preAllocatedBufferSize));
+                    if (key.endsWith(TailFileState.StateKeys.FILENAME) && 
filesToTailSet.contains(value)) {
+                        final int index;
+                        try {
+                            index = Integer.parseInt(key.split("\\.")[1]);
+                        } catch (final RuntimeException e) {
+                            getLogger().warn("Ignoring malformed TailFile 
state key {}", key, e);
+                            continue;
+                        }

Review Comment:
   Is there a particular reason for introducing this try-catch? The Processor 
should control the state content, avoiding potential incorrect formatting.



##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/TailFile.java:
##########
@@ -415,6 +415,7 @@ public void recoverState(final ProcessContext context) 
throws IOException {
 
     private void initStates(final List<String> filesToTail, final Map<String, 
String> statesMap, final boolean isCleared) {
         int fileIndex = 0;
+        final Set<String> filesToTailSet = new HashSet<>(filesToTail);

Review Comment:
   ```suggestion
           final Set<String> uniqueFilesToTail = new HashSet<>(filesToTail);
   ```



-- 
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]

Reply via email to