From c43e283b57f0ec874b15c37cce5ecdcdc331cac0 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Sat, 1 Jun 2024 19:49:36 +0200 Subject: [PATCH] [FIX] socme checks --- .classpath | 2 +- .project | 6 +++ pom.xml | 45 ++++++++++++------- .../kar/archidata/GlobalConfiguration.java | 2 +- .../kar/archidata/dataAccess/DataAccess.java | 12 +++-- src/org/kar/archidata/tools/UuidUtils.java | 2 +- 6 files changed, 44 insertions(+), 25 deletions(-) diff --git a/.classpath b/.classpath index 948a0ab..c84a787 100644 --- a/.classpath +++ b/.classpath @@ -25,7 +25,7 @@ - + diff --git a/.project b/.project index 1cb3dcd..1e3f1c4 100644 --- a/.project +++ b/.project @@ -15,10 +15,16 @@ + + edu.umd.cs.findbugs.plugin.eclipse.findbugsBuilder + + + org.eclipse.jdt.core.javanature org.eclipse.m2e.core.maven2Nature + edu.umd.cs.findbugs.plugin.eclipse.findbugsNature diff --git a/pom.xml b/pom.xml index 729d06f..39b1775 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ archidata 0.10.3 - 21 + 21 3.1 21 21 @@ -120,7 +120,6 @@ jackson-datatype-jsr310 2.17.1 - jakarta.servlet jakarta.servlet-api @@ -170,20 +169,19 @@ org.junit.jupiter junit-jupiter-engine 5.11.0-M2 - test - - - net.revelc.code.formatter - formatter-maven-plugin - 2.23.0 + test - org.apache.maven.plugins - maven-checkstyle-plugin - 3.3.1 + net.revelc.code.formatter + formatter-maven-plugin + 2.23.0 - - + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.3.1 + + src @@ -269,7 +267,7 @@ org.apache.maven.plugins maven-checkstyle-plugin - 3.3.1 + 3.3.1 CheckStyle.xml true @@ -281,7 +279,7 @@ net.revelc.code.formatter formatter-maven-plugin - 2.23.0 + 2.23.0 UTF-8 LF @@ -305,6 +303,23 @@ + + com.github.spotbugs + spotbugs-maven-plugin + 4.8.5.0 + + spotbugs-security-include.xml + spotbugs-security-exclude.xml + + + diff --git a/src/org/kar/archidata/GlobalConfiguration.java b/src/org/kar/archidata/GlobalConfiguration.java index dc2d618..321c7c9c 100644 --- a/src/org/kar/archidata/GlobalConfiguration.java +++ b/src/org/kar/archidata/GlobalConfiguration.java @@ -4,7 +4,7 @@ import org.kar.archidata.db.DBConfig; import org.kar.archidata.tools.ConfigBaseVariable; public class GlobalConfiguration { - public static DBConfig dbConfig = null; + public static final DBConfig dbConfig; static { dbConfig = new DBConfig(ConfigBaseVariable.getDBType(), ConfigBaseVariable.getDBHost(), diff --git a/src/org/kar/archidata/dataAccess/DataAccess.java b/src/org/kar/archidata/dataAccess/DataAccess.java index a14825c..2ec7feb 100644 --- a/src/org/kar/archidata/dataAccess/DataAccess.java +++ b/src/org/kar/archidata/dataAccess/DataAccess.java @@ -969,13 +969,12 @@ public class DataAccess { // uniqueSQLUUID = generatedKeys.getObject(1, UUID.class); /* final Object obj = generatedKeys.getObject(1); final BigInteger bigint = (BigInteger) generatedKeys.getObject(1); uniqueSQLUUID = UuidUtils.asUuid(bigint); final UUID * generatedUUID = (UUID) generatedKeys.getObject(1); System.out.println("UUID généré: " + generatedUUID); */ - final Object obj = generatedKeys.getObject(1); + //final Object obj = generatedKeys.getObject(1); final byte[] tmpid = generatedKeys.getBytes(1); uniqueSQLUUID = UuidUtils.asUuid(tmpid); } else { uniqueSQLID = generatedKeys.getLong(1); } - } else { throw new SQLException("Creating node failed, no ID obtained (1)."); } @@ -985,6 +984,7 @@ public class DataAccess { throw new SQLException("Creating node failed, no ID obtained (2)."); } } + ps.close(); if (primaryKeyField != null) { if (primaryKeyField.getType() == Long.class) { primaryKeyField.set(data, uniqueSQLID); @@ -1228,7 +1228,9 @@ public class DataAccess { } } condition.injectQuery(ps, iii); - return ps.executeUpdate(); + final int out = ps.executeUpdate(); + ps.close(); + return out; } } catch (final SQLException ex) { ex.printStackTrace(); @@ -1574,10 +1576,6 @@ public class DataAccess { return getsWhere(clazz, option); } - public static int delete(final Class clazz, final ID_TYPE id) throws Exception { - return delete(clazz, id, null); - } - /** Delete items with the specific Id (cf @Id) and some options. If the Entity is manage as a softDeleted model, then it is flag as removed (if not already done before). * @param Type of the reference @Id * @param clazz Data model that might remove element diff --git a/src/org/kar/archidata/tools/UuidUtils.java b/src/org/kar/archidata/tools/UuidUtils.java index 7cf37b5..971d3fc 100644 --- a/src/org/kar/archidata/tools/UuidUtils.java +++ b/src/org/kar/archidata/tools/UuidUtils.java @@ -47,7 +47,7 @@ public class UuidUtils { this.base = startingUUID.until(Instant.now(), ChronoUnit.SECONDS); final String serveurBaseUUID = System.getenv("UUID_SERVER_ID"); if (serveurBaseUUID != null) { - long serverId = Long.valueOf(serveurBaseUUID); + long serverId = Long.parseLong(serveurBaseUUID); serverId %= 0xFFFF; this.base += (serverId << (64 - 16)); } else {