Skip to content

Commit

Permalink
apache#1366 - Fixed logging of java.sql.Date
Browse files Browse the repository at this point in the history
  • Loading branch information
Hikarikun92 authored and theit committed May 30, 2023
1 parent 11477bb commit dc04741
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
public final class StringBuilders {

private static final Class<?> timeClass;
private static final Class<?> dateClass;

static {
Class<?> clazz;
Expand All @@ -35,6 +36,13 @@ public final class StringBuilders {
clazz = null;
}
timeClass = clazz;

try {
clazz = Class.forName("java.sql.Date");
} catch(ClassNotFoundException ex) {
clazz = null;
}
dateClass = clazz;
}

private StringBuilders() {
Expand Down Expand Up @@ -110,7 +118,7 @@ public static boolean appendSpecificTypes(final StringBuilder stringBuilder, fin
stringBuilder.append(((Float) obj).floatValue());
} else if (obj instanceof Byte) {
stringBuilder.append(((Byte) obj).byteValue());
} else if (isTime(obj) || obj instanceof java.time.temporal.Temporal) {
} else if (isTime(obj) || isDate(obj) || obj instanceof java.time.temporal.Temporal) {
stringBuilder.append(obj);
} else {
return false;
Expand All @@ -119,12 +127,18 @@ public static boolean appendSpecificTypes(final StringBuilder stringBuilder, fin
}

/*
Check to see if obj is an instance of java.sql.time without requiring the java.sql module.
Check to see if obj is an instance of java.sql.Time without requiring the java.sql module.
*/
private static boolean isTime(final Object obj) {
return timeClass != null && timeClass.isAssignableFrom(obj.getClass());
}

/*
Check to see if obj is an instance of java.sql.Date without requiring the java.sql module.
*/
private static boolean isDate(final Object obj) {
return dateClass != null && dateClass.isAssignableFrom(obj.getClass());
}

/**
* Returns true if the specified section of the left CharSequence equals the specified section of the right
Expand Down

0 comments on commit dc04741

Please sign in to comment.