Repository: nifi
Updated Branches:
  refs/heads/master fb7d6d115 -> b12cf8a6d


NIFI-3671: This closes #1852. Ensure that we use the existing ResourceClaim (if 
it exists) when swapping data in, instead of creating a new one. Otherwise, if 
the ResourceClaim is still writable, then we may archive the data and then 
write to it, which can cause a NullPointerException in FileSystemRepository

Signed-off-by: joewitt <joew...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/b12cf8a6
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/b12cf8a6
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/b12cf8a6

Branch: refs/heads/master
Commit: b12cf8a6d28c2a025831fff9363adf2b13199071
Parents: fb7d6d1
Author: Mark Payne <marka...@hotmail.com>
Authored: Wed May 24 13:47:36 2017 -0400
Committer: joewitt <joew...@apache.org>
Committed: Wed May 24 14:21:18 2017 -0400

----------------------------------------------------------------------
 .../repository/schema/ContentClaimFieldMap.java          | 10 +++++++++-
 .../repository/schema/ResourceClaimFieldMap.java         | 11 ++++++++++-
 2 files changed, 19 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/b12cf8a6/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-flowfile-repo-serialization/src/main/java/org/apache/nifi/controller/repository/schema/ContentClaimFieldMap.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-flowfile-repo-serialization/src/main/java/org/apache/nifi/controller/repository/schema/ContentClaimFieldMap.java
 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-flowfile-repo-serialization/src/main/java/org/apache/nifi/controller/repository/schema/ContentClaimFieldMap.java
index b218ee6..eddde34 100644
--- 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-flowfile-repo-serialization/src/main/java/org/apache/nifi/controller/repository/schema/ContentClaimFieldMap.java
+++ 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-flowfile-repo-serialization/src/main/java/org/apache/nifi/controller/repository/schema/ContentClaimFieldMap.java
@@ -112,7 +112,15 @@ public class ContentClaimFieldMap implements Record {
         final Long length = (Long) 
claimRecord.getFieldValue(ContentClaimSchema.CONTENT_CLAIM_LENGTH);
         final Long resourceOffset = (Long) 
claimRecord.getFieldValue(ContentClaimSchema.RESOURCE_CLAIM_OFFSET);
 
-        final ResourceClaim resourceClaim = 
resourceClaimManager.newResourceClaim(container, section, identifier, 
lossTolerant, false);
+        // Make sure that we preserve the existing ResourceClaim, if there is 
already one held by the Resource Claim Manager
+        // because we need to honor its determination of whether or not the 
claim is writable. If the Resource Claim Manager
+        // does not have a copy of this Resource Claim, then we can go ahead 
and just create one and assume that it is not
+        // writable (because if it were writable, then the Resource Claim 
Manager would know about it).
+        ResourceClaim resourceClaim = 
resourceClaimManager.getResourceClaim(container, section, identifier);
+        if (resourceClaim == null) {
+            resourceClaim = resourceClaimManager.newResourceClaim(container, 
section, identifier, lossTolerant, false);
+        }
+
         final StandardContentClaim contentClaim = new 
StandardContentClaim(resourceClaim, resourceOffset);
         contentClaim.setLength(length);
 

http://git-wip-us.apache.org/repos/asf/nifi/blob/b12cf8a6/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-flowfile-repo-serialization/src/main/java/org/apache/nifi/controller/repository/schema/ResourceClaimFieldMap.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-flowfile-repo-serialization/src/main/java/org/apache/nifi/controller/repository/schema/ResourceClaimFieldMap.java
 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-flowfile-repo-serialization/src/main/java/org/apache/nifi/controller/repository/schema/ResourceClaimFieldMap.java
index afa19ea..bc4741f 100644
--- 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-flowfile-repo-serialization/src/main/java/org/apache/nifi/controller/repository/schema/ResourceClaimFieldMap.java
+++ 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-flowfile-repo-serialization/src/main/java/org/apache/nifi/controller/repository/schema/ResourceClaimFieldMap.java
@@ -58,7 +58,16 @@ public class ResourceClaimFieldMap implements Record {
         final String identifier = (String) 
record.getFieldValue(ContentClaimSchema.CLAIM_IDENTIFIER);
         final Boolean lossTolerant = (Boolean) 
record.getFieldValue(ContentClaimSchema.LOSS_TOLERANT);
 
-        return claimManager.newResourceClaim(container, section, identifier, 
lossTolerant, false);
+        // Make sure that we preserve the existing ResourceClaim, if there is 
already one held by the Resource Claim Manager
+        // because we need to honor its determination of whether or not the 
claim is writable. If the Resource Claim Manager
+        // does not have a copy of this Resource Claim, then we can go ahead 
and just create one and assume that it is not
+        // writable (because if it were writable, then the Resource Claim 
Manager would know about it).
+        ResourceClaim resourceClaim = claimManager.getResourceClaim(container, 
section, identifier);
+        if (resourceClaim == null) {
+            resourceClaim = claimManager.newResourceClaim(container, section, 
identifier, lossTolerant, false);
+        }
+
+        return resourceClaim;
     }
 
     @Override

Reply via email to