Skip to content

Commit b779ed0

Browse files
SOLR-17379: Fix date parsing in Java 23, remove Lucene TestSecurityManager (#3154)
* Fix system exit in test Co-authored-by: Chris Hostetter <[email protected]>
1 parent cc9a0f8 commit b779ed0

File tree

4 files changed

+35
-34
lines changed

4 files changed

+35
-34
lines changed

gradle/testing/randomization.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ allprojects {
213213
javaSecurityPolicy: javaSecurityPolicy
214214
)
215215
)
216-
systemProperty 'java.security.manager', "org.apache.lucene.tests.util.TestSecurityManager"
216+
systemProperty 'java.security.manager', "default"
217217

218218
def gradleUserHome = project.gradle.getGradleUserHomeDir()
219219
systemProperty 'gradle.lib.dir', Paths.get(project.class.location.toURI()).parent.toAbsolutePath().toString().replace('\\', '/')

solr/core/src/java/org/apache/solr/update/processor/ParseDateFieldUpdateProcessorFactory.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,13 @@ public static Object parsePossibleDate(
186186
return Date.from(parseInstant(parser, srcStringVal, parsePosition));
187187
} catch (DateTimeParseException e) {
188188
if (log.isDebugEnabled()) {
189-
log.debug("value '{}' is not parseable with format '{}'", srcStringVal, parser);
189+
log.debug(
190+
"value '{}' is not parseable with format '{}' (using {} + {})",
191+
srcStringVal,
192+
parser,
193+
parser.getLocale(),
194+
parser.getZone(),
195+
e);
190196
}
191197
}
192198
}

solr/core/src/test/org/apache/solr/security/BasicAuthIntegrationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,12 @@ public void testBasicAuth() throws Exception {
295295
verifySecurityStatus(cl, baseUrl + "/admin/info/key", "key", NOT_NULL_PREDICATE, 20);
296296
assertAuthMetricsMinimums(17, 8, 8, 1, 0, 0);
297297

298-
String[] toolArgs = new String[] {"status", "--solr-url", baseUrl};
298+
String[] toolArgs =
299+
new String[] {"status", "--solr-url", baseUrl, "--credentials", "harry:HarryIsUberCool"};
299300
ByteArrayOutputStream baos = new ByteArrayOutputStream();
300301
PrintStream stdoutSim = new PrintStream(baos, true, StandardCharsets.UTF_8.name());
301302
StatusTool tool = new StatusTool(stdoutSim);
302303
try {
303-
System.setProperty("basicauth", "harry:HarryIsUberCool");
304304
tool.runTool(SolrCLI.processCommandLineArgs(tool, toolArgs));
305305
Map<?, ?> obj = (Map<?, ?>) Utils.fromJSON(new ByteArrayInputStream(baos.toByteArray()));
306306
assertTrue(obj.containsKey("version"));

solr/core/src/test/org/apache/solr/update/processor/ParsingFieldUpdateProcessorsTest.java

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.time.ZoneOffset;
2727
import java.time.ZonedDateTime;
2828
import java.time.format.DateTimeFormatter;
29+
import java.time.format.DateTimeParseException;
2930
import java.time.temporal.TemporalAccessor;
3031
import java.util.Date;
3132
import java.util.HashMap;
@@ -1064,43 +1065,37 @@ public void testAKSTZone() throws IOException {
10641065
final String inputString = "Thu Nov 13 04:35:51 AKST 2008"; // asctime + timezone1
10651066

10661067
final long expectTs = 1226583351000L;
1067-
assertEquals(
1068-
expectTs,
1069-
DateTimeFormatter.ofPattern(dateFormat, Locale.ENGLISH)
1070-
.withZone(ZoneId.of("UTC"))
1071-
.parse(inputString, Instant::from)
1072-
.toEpochMilli());
10731068

1074-
// ensure english locale and root locale return the same date
1075-
assertEquals(
1076-
expectTs + "",
1077-
DateTimeFormatter.ofPattern(dateFormat, Locale.ENGLISH)
1078-
.withZone(ZoneId.of("UTC"))
1079-
.parse(inputString, Instant::from)
1080-
.toEpochMilli(),
1081-
DateTimeFormatter.ofPattern(dateFormat, Locale.ROOT)
1082-
.withZone(ZoneId.of("UTC"))
1083-
.parse(inputString, Instant::from)
1084-
.toEpochMilli());
1069+
try {
1070+
// ensure english locale and root locale return the same date
1071+
assertEquals(
1072+
expectTs,
1073+
DateTimeFormatter.ofPattern(dateFormat, Locale.ENGLISH)
1074+
.withZone(ZoneId.of("UTC"))
1075+
.parse(inputString, Instant::from)
1076+
.toEpochMilli());
1077+
1078+
assertEquals(
1079+
expectTs,
1080+
DateTimeFormatter.ofPattern(dateFormat, Locale.ROOT)
1081+
.withZone(ZoneId.of("UTC"))
1082+
.parse(inputString, Instant::from)
1083+
.toEpochMilli());
1084+
} catch (DateTimeParseException e) {
1085+
// If the JVM's java.locale.providers can't parse these, there is no hope of this test passing
1086+
assumeNoException("JVM's Locale provider is incompatible with this test", e);
1087+
}
10851088

10861089
assertParsedDate(
10871090
inputString,
10881091
Date.from(Instant.ofEpochMilli(expectTs)),
10891092
"parse-date-patterns-default-config");
10901093

1091-
// A bug in Java 9 (not in 8) causes this to fail! (not fixed yet?!)
1092-
// see https://bugs.openjdk.java.net/browse/JDK-8189784
1093-
if (System.getProperty("java.version").startsWith("1.8.")) {
1094-
// with daylight savings time timezone
1095-
assertParsedDate(
1096-
"Fri Oct 7 05:14:15 AKDT 2005",
1097-
Date.from(inst20051007131415()),
1098-
"parse-date-patterns-default-config");
1099-
} else {
1100-
System.err.println(
1101-
"Didn't test AKDT because only Java 1.8 does this right! This Java version is: "
1102-
+ System.getProperty("java.version"));
1103-
}
1094+
// with daylight savings time timezone
1095+
assertParsedDate(
1096+
"Fri Oct 7 05:14:15 AKDT 2005",
1097+
Date.from(inst20051007131415()),
1098+
"parse-date-patterns-default-config");
11041099
}
11051100

11061101
public void testEDTZone() throws IOException {

0 commit comments

Comments
 (0)