Skip to content

Commit

Permalink
LDEV-5092 - addressing the ConcurrentModificationException issue
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Oct 7, 2024
1 parent 078d302 commit 1d7eefe
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
3 changes: 2 additions & 1 deletion core/src/main/java/lucee/commons/i18n/FormatUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.Map;
import java.util.TimeZone;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

import lucee.commons.date.TimeZoneConstants;
import lucee.commons.io.IOUtil;
Expand Down Expand Up @@ -121,7 +122,7 @@ public static List<FormatterWrapper> getAllFormats(Locale locale, TimeZone timeZ
sr = cfmlFormats.get(key);
if (sr == null || (formatter = sr.get()) == null) {

formatter = new ArrayList<>();
formatter = new CopyOnWriteArrayList<>();

for (FormatterWrapper dtf: getCFMLFormats(locale, timeZone, lenient)) {
formatter.add(dtf);
Expand Down
19 changes: 11 additions & 8 deletions core/src/main/java/lucee/runtime/op/date/DateCaster.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,15 @@ public final class DateCaster {
// private static short MODE_MONTH_STR=2;
// private static short MODE_NONE=4;
private static long DEFAULT_VALUE = Long.MIN_VALUE;

private static DateTimeUtil util = DateTimeUtil.getInstance();
public static boolean classicStyle = false;

private static final int SORT_AFTER_FIRST = 500;
private static final int SORT_AFTER = 10000;

private static boolean firstCountCheck = true;
private static int countCheck = 0;

/**
* converts an Object to a DateTime Object (Advanced but slower)
*
Expand Down Expand Up @@ -295,10 +300,8 @@ public static DateTime toDateTime(Locale locale, String str, TimeZone tz, DateTi
return (dt == null) ? defaultValue : dt;
}

private static int count = 0;

public static DateTime toDateTimeNew(Locale locale, String str, TimeZone tz, DateTime defaultValue, boolean useCommomDateParserAsWell) {
count++;
countCheck++;
str = str.trim();
tz = ThreadLocalPageContext.getTimeZone(tz);

Expand All @@ -317,16 +320,16 @@ public static DateTime toDateTimeNew(Locale locale, String str, TimeZone tz, Dat
}
}
finally {
if (count > 10) {
if (countCheck > (firstCountCheck ? SORT_AFTER_FIRST : SORT_AFTER)) {
synchronized (all) {
if (count > 500) {
if (countCheck > (firstCountCheck ? SORT_AFTER_FIRST : SORT_AFTER)) {
all.sort(Comparator.comparingInt(x -> -x.successCount));
count = 0;
countCheck = 0;
firstCountCheck = false;
}
}
}
}

if (useCommomDateParserAsWell) return DateCaster.toDateSimple(str, CONVERTING_TYPE_NONE, true, tz, defaultValue);
return defaultValue;
}
Expand Down
2 changes: 1 addition & 1 deletion loader/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project default="core" basedir="." name="Lucee"
xmlns:resolver="antlib:org.apache.maven.resolver.ant">

<property name="version" value="6.2.0.93-SNAPSHOT"/>
<property name="version" value="6.2.0.94-SNAPSHOT"/>

<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml">
<classpath>
Expand Down
2 changes: 1 addition & 1 deletion loader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.lucee</groupId>
<artifactId>lucee</artifactId>
<version>6.2.0.93-SNAPSHOT</version>
<version>6.2.0.94-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Lucee Loader Build</name>
Expand Down

0 comments on commit 1d7eefe

Please sign in to comment.