Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SOLR-17379: Fix date parsing in Java 23, remove Lucene TestSecurityManager #3154

Merged
merged 4 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle/testing/randomization.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ allprojects {
javaSecurityPolicy: javaSecurityPolicy
)
)
systemProperty 'java.security.manager', "org.apache.lucene.tests.util.TestSecurityManager"
systemProperty 'java.security.manager', "default"

def gradleUserHome = project.gradle.getGradleUserHomeDir()
systemProperty 'gradle.lib.dir', Paths.get(project.class.location.toURI()).parent.toAbsolutePath().toString().replace('\\', '/')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,13 @@ public static Object parsePossibleDate(
return Date.from(parseInstant(parser, srcStringVal, parsePosition));
} catch (DateTimeParseException e) {
if (log.isDebugEnabled()) {
log.debug("value '{}' is not parseable with format '{}'", srcStringVal, parser);
log.debug(
"value '{}' is not parseable with format '{}' (using {} + {})",
srcStringVal,
parser,
parser.getLocale(),
parser.getZone(),
e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,12 @@ public void testBasicAuth() throws Exception {
verifySecurityStatus(cl, baseUrl + "/admin/info/key", "key", NOT_NULL_PREDICATE, 20);
assertAuthMetricsMinimums(17, 8, 8, 1, 0, 0);

String[] toolArgs = new String[] {"status", "--solr-url", baseUrl};
String[] toolArgs =
new String[] {"status", "--solr-url", baseUrl, "--credentials", "harry:HarryIsUberCool"};
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream stdoutSim = new PrintStream(baos, true, StandardCharsets.UTF_8.name());
StatusTool tool = new StatusTool(stdoutSim);
try {
System.setProperty("basicauth", "harry:HarryIsUberCool");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any chance that this pattern shows up anywhere else and or is suggested in docs? Magic system variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea, clearly it didn't work haha.

tool.runTool(SolrCLI.processCommandLineArgs(tool, toolArgs));
Map<?, ?> obj = (Map<?, ?>) Utils.fromJSON(new ByteArrayInputStream(baos.toByteArray()));
assertTrue(obj.containsKey("version"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.temporal.TemporalAccessor;
import java.util.Date;
import java.util.HashMap;
Expand Down Expand Up @@ -1064,43 +1065,37 @@ public void testAKSTZone() throws IOException {
final String inputString = "Thu Nov 13 04:35:51 AKST 2008"; // asctime + timezone1

final long expectTs = 1226583351000L;
assertEquals(
expectTs,
DateTimeFormatter.ofPattern(dateFormat, Locale.ENGLISH)
.withZone(ZoneId.of("UTC"))
.parse(inputString, Instant::from)
.toEpochMilli());

// ensure english locale and root locale return the same date
assertEquals(
expectTs + "",
DateTimeFormatter.ofPattern(dateFormat, Locale.ENGLISH)
.withZone(ZoneId.of("UTC"))
.parse(inputString, Instant::from)
.toEpochMilli(),
DateTimeFormatter.ofPattern(dateFormat, Locale.ROOT)
.withZone(ZoneId.of("UTC"))
.parse(inputString, Instant::from)
.toEpochMilli());
try {
// ensure english locale and root locale return the same date
assertEquals(
expectTs,
DateTimeFormatter.ofPattern(dateFormat, Locale.ENGLISH)
.withZone(ZoneId.of("UTC"))
.parse(inputString, Instant::from)
.toEpochMilli());

assertEquals(
expectTs,
DateTimeFormatter.ofPattern(dateFormat, Locale.ROOT)
.withZone(ZoneId.of("UTC"))
.parse(inputString, Instant::from)
.toEpochMilli());
} catch (DateTimeParseException e) {
// If the JVM's java.locale.providers can't parse these, there is no hope of this test passing
assumeNoException("JVM's Locale provider is incompatible with this test", e);
}

assertParsedDate(
inputString,
Date.from(Instant.ofEpochMilli(expectTs)),
"parse-date-patterns-default-config");

// A bug in Java 9 (not in 8) causes this to fail! (not fixed yet?!)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice clean up

// see https://bugs.openjdk.java.net/browse/JDK-8189784
if (System.getProperty("java.version").startsWith("1.8.")) {
// with daylight savings time timezone
assertParsedDate(
"Fri Oct 7 05:14:15 AKDT 2005",
Date.from(inst20051007131415()),
"parse-date-patterns-default-config");
} else {
System.err.println(
"Didn't test AKDT because only Java 1.8 does this right! This Java version is: "
+ System.getProperty("java.version"));
}
// with daylight savings time timezone
assertParsedDate(
"Fri Oct 7 05:14:15 AKDT 2005",
Date.from(inst20051007131415()),
"parse-date-patterns-default-config");
}

public void testEDTZone() throws IOException {
Expand Down
Loading