From 11b45cb3f16dbd2bca94c36b866e7307b2bb5f53 Mon Sep 17 00:00:00 2001 From: "angel.herce" Date: Tue, 29 Apr 2025 12:05:40 +0200 Subject: [PATCH] fix: Correct NullPointerException --- .../sdms/common/file/DefaultTemporalFileManager.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ontimize-jee-sdms-common/src/main/java/com/ontimize/jee/sdms/common/file/DefaultTemporalFileManager.java b/ontimize-jee-sdms-common/src/main/java/com/ontimize/jee/sdms/common/file/DefaultTemporalFileManager.java index b1aa400..c66e217 100644 --- a/ontimize-jee-sdms-common/src/main/java/com/ontimize/jee/sdms/common/file/DefaultTemporalFileManager.java +++ b/ontimize-jee-sdms-common/src/main/java/com/ontimize/jee/sdms/common/file/DefaultTemporalFileManager.java @@ -27,8 +27,8 @@ public File create( final String name, final InputStream inputStream ) throws IO final File file; if( directory.exists() && directory.isDirectory() ) file = File.createTempFile( name, ".tmp", directory ); else file = File.createTempFile( name, ".tmp" ); - try( FileOutputStream fos = new FileOutputStream( file)) { - inputStream.transferTo(fos); + try( FileOutputStream fos = new FileOutputStream( file )) { + inputStream.transferTo( fos ); } if( FILES.get() == null ) FILES.set( new ArrayList<>() ); FILES.get().add( file ); @@ -44,7 +44,7 @@ public File create( final InputStream inputStream ) throws IOException { public void delete( final File file ) throws IOException { if( FILES.get() == null ) return; final Optional result = FILES.get().stream() - .filter( target -> target.getAbsolutePath().equals( file.getAbsolutePath() ) ) + .filter( target -> target.getAbsolutePath().equals( file.getAbsolutePath() )) .findFirst(); if( result.isPresent() ){ final File target = result.get(); @@ -55,9 +55,8 @@ public void delete( final File file ) throws IOException { @Override public void cleanUp() throws IOException { - for( final File file : FILES.get() ){ - if( file.exists() ) Files.delete( file.toPath() ); - } + if( FILES.get() == null ) return; + for( final File file : FILES.get() ) if( file.exists() ) Files.delete( file.toPath() ); FILES.remove(); } }