From 5b71ae6856ee8a64108ec00127b49cb4f9492af5 Mon Sep 17 00:00:00 2001 From: "Matteo Franci a.k.a. Fugerit" Date: Thu, 14 Sep 2023 19:24:58 +0200 Subject: [PATCH] Fix sonar cloud issues --- .../org/fugerit/java/core/jvfs/util/JFileUtilCP.java | 2 +- .../java/org/fugerit/java/core/cfg/CloseHelper.java | 4 ++-- .../org/fugerit/java/core/cfg/xml/PropertyHolder.java | 6 +++--- .../java/core/io/file/DeleteRecurseFileFun.java | 3 ++- .../fugerit/java/core/lang/helpers/ClassHelper.java | 10 +++------- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/fj-core-jvfs/src/main/java/org/fugerit/java/core/jvfs/util/JFileUtilCP.java b/fj-core-jvfs/src/main/java/org/fugerit/java/core/jvfs/util/JFileUtilCP.java index 24741047..0fbb63bd 100644 --- a/fj-core-jvfs/src/main/java/org/fugerit/java/core/jvfs/util/JFileUtilCP.java +++ b/fj-core-jvfs/src/main/java/org/fugerit/java/core/jvfs/util/JFileUtilCP.java @@ -41,7 +41,7 @@ public static int copyFileRecurseForceVerbose( JFile from, JFile to ) throws IOE } public static int copyFile(JFile from, JFile to, boolean recurse, boolean force, boolean verbose) throws IOException { - return copyFile( from, to, recurse, force, verbose, ( f ) -> true ); + return copyFile( from, to, recurse, force, verbose, f -> true ); } private static int copyFileRecurse( JFile from, JFile to, boolean recurse, boolean force, boolean verbose, Predicate filter, int res ) throws IOException { diff --git a/fj-core/src/main/java/org/fugerit/java/core/cfg/CloseHelper.java b/fj-core/src/main/java/org/fugerit/java/core/cfg/CloseHelper.java index b196a6c4..190690e6 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/cfg/CloseHelper.java +++ b/fj-core/src/main/java/org/fugerit/java/core/cfg/CloseHelper.java @@ -37,13 +37,13 @@ public static void close( Closeable ac ) throws ConfigException { public static void closeRuntimeEx( AutoCloseable ac ) { if ( ac != null ) { - SafeFunction.apply( () -> ac.close(), e -> { throw ConfigRuntimeException.convertEx( BASIC_CLOSE_MESSAGE+ac , e ); } ); + SafeFunction.apply( ac::close, e -> { throw ConfigRuntimeException.convertEx( BASIC_CLOSE_MESSAGE+ac , e ); } ); } } public static void closeRuntimeEx( Closeable ac ) { if ( ac != null ) { - SafeFunction.apply( () -> ac.close(), e -> { throw ConfigRuntimeException.convertEx( BASIC_CLOSE_MESSAGE+ac , e ); } ); + SafeFunction.apply( ac::close, e -> { throw ConfigRuntimeException.convertEx( BASIC_CLOSE_MESSAGE+ac , e ); } ); } } diff --git a/fj-core/src/main/java/org/fugerit/java/core/cfg/xml/PropertyHolder.java b/fj-core/src/main/java/org/fugerit/java/core/cfg/xml/PropertyHolder.java index 88fd510b..e7e2ef9b 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/cfg/xml/PropertyHolder.java +++ b/fj-core/src/main/java/org/fugerit/java/core/cfg/xml/PropertyHolder.java @@ -117,10 +117,10 @@ private static void loadWorker( InputStream is, Properties props, boolean xml, S private static void handleException( String path, Exception e, String unsafe, String usafeMessage ) throws IOException { if ( UNSAFE_TRUE.equalsIgnoreCase( unsafe ) || UNSAFE_WARN.equalsIgnoreCase( unsafe ) ) { String unsafeMessafeWork = usafeMessage+" "; - if ( StringUtils.isNotEmpty( unsafeMessafeWork ) ) { - unsafeMessafeWork+=" "; + if ( StringUtils.isNotEmpty( usafeMessage ) ) { + unsafeMessafeWork+= usafeMessage+" "; } - unsafeMessafeWork = path + ", " + unsafe + ", " + e; + unsafeMessafeWork+= path + ", " + unsafe + ", " + e; if ( UNSAFE_WARN.equalsIgnoreCase( unsafe ) ) { log.warn( "Error loading unsafe property holder : {}", unsafeMessafeWork ); } else { diff --git a/fj-core/src/main/java/org/fugerit/java/core/io/file/DeleteRecurseFileFun.java b/fj-core/src/main/java/org/fugerit/java/core/io/file/DeleteRecurseFileFun.java index 57e06967..22edd345 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/io/file/DeleteRecurseFileFun.java +++ b/fj-core/src/main/java/org/fugerit/java/core/io/file/DeleteRecurseFileFun.java @@ -2,6 +2,7 @@ import java.io.File; import java.io.IOException; +import java.nio.file.Files; import lombok.extern.slf4j.Slf4j; @@ -16,7 +17,7 @@ public class DeleteRecurseFileFun extends AbstractFileFun { @Override public void handleFile(File file) throws IOException { - boolean res = file.delete(); + boolean res = Files.deleteIfExists( file.toPath() ); if ( !res ) { log.warn( "false result on file.delete() : {}", file ); } diff --git a/fj-core/src/main/java/org/fugerit/java/core/lang/helpers/ClassHelper.java b/fj-core/src/main/java/org/fugerit/java/core/lang/helpers/ClassHelper.java index 790c3a32..5e523e10 100644 --- a/fj-core/src/main/java/org/fugerit/java/core/lang/helpers/ClassHelper.java +++ b/fj-core/src/main/java/org/fugerit/java/core/lang/helpers/ClassHelper.java @@ -52,14 +52,10 @@ public static Object newInstance( String type ) throws ClassNotFoundException, N ClassLoader classLoader = getDefaultClassLoader(); Class c = classLoader.loadClass( type ); result = c.getDeclaredConstructor().newInstance(); + } catch (ClassNotFoundException | NoSuchMethodException e) { + throw e; } catch (Exception e) { - if ( e instanceof ClassNotFoundException ) { - throw (ClassNotFoundException)e; - } else if ( e instanceof NoSuchMethodException ) { - throw (NoSuchMethodException)e; - } else { - throw ConfigException.convertExMethod( "newInstance" , e ); - } + throw ConfigException.convertExMethod( "newInstance" , e ); } return result; }