[ 
https://issues.apache.org/jira/browse/NIFI-6882?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16991236#comment-16991236
 ] 

Alessandro D'Armiento commented on NIFI-6882:
---------------------------------------------

Taking a look at TestPutFile, there is the `testCreateDirectory()` method which 
seems to already enforce the creation of the folder when it doesn't exist.

 
{code:java}
@Test
public void testCreateDirectory() throws IOException {
 final TestRunner runner = TestRunners.newTestRunner(new PutFile());
 String newDir = targetDir.getAbsolutePath()+"/new-folder";
 Files.deleteIfExists(new File(newDir).toPath());                <----- I added 
this one to make sure the folder didn't already exist
 runner.setProperty(PutFile.DIRECTORY, newDir);
 runner.setProperty(PutFile.CONFLICT_RESOLUTION, PutFile.REPLACE_RESOLUTION);

 Map<String, String> attributes = new HashMap<>();
 attributes.put(CoreAttributes.FILENAME.key(), "targetFile.txt");
 runner.enqueue("Hello world!!".getBytes(), attributes);
 runner.run();
 runner.assertAllFlowFilesTransferred(FetchFile.REL_SUCCESS, 1);
 Path targetPath = Paths.get(TARGET_DIRECTORY + "/new-folder/targetFile.txt");
 byte[] content = Files.readAllBytes(targetPath);
 assertEquals("Hello world!!", new String(content));
}{code}
I think that maybe the problem here is more complex, but is drowned somewhere 
where it is unchecked, eventually producing the NPE. I'll further investigate 
for example what happens if your user does not have the writing permission on 
the folder, or the executing permission in one of the super-folder you have to 
traverse (I'm not sure if this was already tested or not)

> PutFile throws NullPointerException if destination directory doesn't exist
> --------------------------------------------------------------------------
>
>                 Key: NIFI-6882
>                 URL: https://issues.apache.org/jira/browse/NIFI-6882
>             Project: Apache NiFi
>          Issue Type: Bug
>          Components: Extensions
>    Affects Versions: 1.10.0
>            Reporter: Mark Payne
>            Priority: Critical
>
> I have a PutFile processor that is configured to create directories if they 
> don't exist. I have the directory set to "heap-dumps", which does not exist. 
> When data came into the processor, it started throwing the following NPE:
> {code}
> 2019-11-18 16:46:14,879 ERROR [Timer-Driven Process Thread-2] 
> o.a.nifi.processors.standard.PutFile 
> PutFile[id=0b173f77-d60a-1ce8-d59e-4a9aeff49dbf] Penalizing 
> StandardFlowFileRecord[uuid=38a6849b-965b-46b2-96d3-fe37a1c22cf8,claim=StandardContentClaim
>  [resourceClaim=StandardResourceClaim[id=1574113470589-2, container=default, 
> section=2], offset=0, 
> length=1139822320],offset=0,name=heap.bin.gz,size=1139822320] and 
> transferring to failure due to java.lang.NullPointerException: 
> java.lang.NullPointerException
> java.lang.NullPointerException: null
>         at java.nio.file.Files.provider(Files.java:97)
>         at java.nio.file.Files.exists(Files.java:2385)
>         at 
> org.apache.nifi.processors.standard.PutFile.onTrigger(PutFile.java:243)
>         at 
> org.apache.nifi.processor.AbstractProcessor.onTrigger(AbstractProcessor.java:27)
>         at 
> org.apache.nifi.controller.StandardProcessorNode.onTrigger(StandardProcessorNode.java:1176)
>         at 
> org.apache.nifi.controller.tasks.ConnectableTask.invoke(ConnectableTask.java:213)
>         at 
> org.apache.nifi.controller.scheduling.TimerDrivenSchedulingAgent$1.run(TimerDrivenSchedulingAgent.java:117)
>         at org.apache.nifi.engine.FlowEngine$2.run(FlowEngine.java:110)
>         at 
> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
>         at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
>         at 
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
>         at 
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
>         at 
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
>         at 
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
>         at java.lang.Thread.run(Thread.java:745)
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to