diff --git a/java/src/main/java/com/genexus/db/driver/GXDBMSpostgresql.java b/java/src/main/java/com/genexus/db/driver/GXDBMSpostgresql.java index fad14605e..50c925202 100644 --- a/java/src/main/java/com/genexus/db/driver/GXDBMSpostgresql.java +++ b/java/src/main/java/com/genexus/db/driver/GXDBMSpostgresql.java @@ -80,32 +80,44 @@ public boolean ReferentialIntegrity(SQLException e) return false; } + private static String safeSQLState(SQLException e) + { + String s = (e == null) ? null : e.getSQLState(); + return (s == null) ? "" : s.toLowerCase(); + } + + private static String safeMessage(SQLException e) + { + String m = (e == null) ? null : e.getMessage(); + return (m == null) ? "" : m.toLowerCase(); + } + public boolean DuplicateKeyValue(SQLException e) { - String sqlstate = e.getSQLState().toLowerCase(); + String sqlstate = safeSQLState(e); //23505 duplicate key violates unique constraint xxx if (sqlstate.indexOf("23505")>=0){ return true; }else { - String msg = e.getMessage().toLowerCase(); + String msg = safeMessage(e); return (msg.indexOf("duplicate key") >= 0 && msg.indexOf("unique") >= 0); } } public boolean ObjectLocked(SQLException e) { - String sqlstate = e.getSQLState().toLowerCase(); + String sqlstate = safeSQLState(e); String sqlstateCause = ""; if (e.getCause() != null && e.getCause() instanceof SQLException) - sqlstateCause = ((SQLException)e.getCause()).getSQLState().toLowerCase(); + sqlstateCause = safeSQLState((SQLException)e.getCause()); return sqlstate.contains("55p03") || sqlstateCause.contains("55p03"); } public boolean ObjectNotFound(SQLException e) { - String sqlstate = e.getSQLState().toLowerCase(); - String msg = e.getMessage().toLowerCase(); + String sqlstate = safeSQLState(e); + String msg = safeMessage(e); //42704 index xxx does not exist //42P01 relation tableName does not exist //42p06 schema already exists diff --git a/java/src/main/java/com/genexus/db/driver/GXPreparedStatement.java b/java/src/main/java/com/genexus/db/driver/GXPreparedStatement.java index 6f5808264..609c7ad98 100644 --- a/java/src/main/java/com/genexus/db/driver/GXPreparedStatement.java +++ b/java/src/main/java/com/genexus/db/driver/GXPreparedStatement.java @@ -1414,8 +1414,9 @@ public void setBLOBFile(int index, String fileName, boolean isMultiMedia) throws if (webContext instanceof com.genexus.webpanels.HttpContextWeb) { if (ApplicationContext.getInstance().isSpringBootApp() && ! new File(fileName).isAbsolute()) { - if (fileName.startsWith(webContext.getContextPath())) - fileName = fileName.replaceFirst(webContext.getContextPath(), "").substring(1); + String ctxPath = webContext.getContextPath(); + if (ctxPath != null && !ctxPath.isEmpty() && fileName.startsWith(ctxPath)) + fileName = fileName.substring(ctxPath.length() + 1); } else fileName = ((com.genexus.webpanels.HttpContextWeb) webContext).getRealPath(fileName); @@ -1424,9 +1425,10 @@ public void setBLOBFile(int index, String fileName, boolean isMultiMedia) throws { if (!webContext.getDefaultPath().isEmpty() && ! new File(fileName).isAbsolute()) { - if (fileName.startsWith(webContext.getContextPath())) + String ctxPath = webContext.getContextPath(); + if (ctxPath != null && !ctxPath.isEmpty() && fileName.startsWith(ctxPath)) { - fileName = fileName.substring(webContext.getContextPath().length() +1); + fileName = fileName.substring(ctxPath.length() +1); } fileName = webContext.getDefaultPath() + File.separator + fileName;