-
Notifications
You must be signed in to change notification settings - Fork 861
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
Allow SDK to build on JDK 17 #3037
Conversation
<property name="message" value="NEVER use System.getenv or System.getProperty. Create and use a | ||
SystemSetting, instead."/> | ||
<property name="ignoreComments" value="true"/> | ||
</module> | ||
|
||
<module name="Regexp"> | ||
<property name="format" value="SystemSetting\s*(\.|::)\s*getStringValueFromEnvironmentVariable"/> | ||
<property name="illegalPattern" value="true"/> | ||
<property name="message" value="Are you being naughty and not creating a SystemSetting? Don't you know that | ||
your customers want both system properties AND environment variables? Are you REALLY sure you want to use | ||
this and not support a system property?"/> | ||
<property name="ignoreComments" value="true"/> | ||
</module> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note for reviewers: This was modified to really push people to use SystemSetting, because that's the only mechanism that supports environment variable mocking, now. We expect everyone to create new SystemSettings to support both properties and environment variables. If they really want to break that, then they can use the static SystemSetting.getStringValueFromEnvironmentVariable
(long to be annoying to write), and they still have to add a checkstyle suppression to do it.
@@ -39,7 +39,7 @@ public static EnvironmentVariableCredentialsProvider create() { | |||
protected Optional<String> loadSetting(SystemSetting setting) { | |||
// CHECKSTYLE:OFF - Customers should be able to specify a credentials provider that only looks at the environment | |||
// variables, but not the system properties. For that reason, we're only checking the environment variable here. | |||
return Optional.ofNullable(System.getenv(setting.environmentVariable())); | |||
return SystemSetting.getStringValueFromEnvironmentVariable(setting.environmentVariable()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note for reviewer: Non-Mockito change. This uses SystemSetting to support mocking.
/** | ||
* Access the underlying delegate stream, for testing purposes. | ||
*/ | ||
@SdkTestInternalApi | ||
public InputStream delegate() { | ||
return in; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to reviewer: Our existing tests relied on reflection to access 'in', which does not work in JDK 17. Now, we expose it via a test API. This should be okay, since this is a protected (not public) API.
connectionInterceptor = safeFunction(connection -> new DelegateHttpURLConnection(connection) { | ||
@Override | ||
public int getResponseCode() { | ||
throw new NullPointerException(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to reviewer: Mockito can no longer spy on classes loaded by the bootstrap class loader in JDK 17, so we had to do the method overriding manually.
@Test | ||
public void InstantAsStringAttributeConverterNotAcceptOffsetTimeTest() { | ||
assertFails(() -> transformTo(CONVERTER, EnhancedAttributeValue.fromString("1988-05-21T00:12:00+01:00") | ||
.toAttributeValue())); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to reviewer: JDK 17 now supports parsing offset times. There shouldn't be a problem supporting this now, so I removed the assertion that we do not support it.
<dependency> | ||
<groupId>org.bouncycastle</groupId> | ||
<artifactId>bcpkix-jdk15on</artifactId> | ||
<version>1.70</version> | ||
<scope>compile</scope> | ||
</dependency> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to reviewer: Netty uses JDK internals to generate self-signed certs for our netty services we spin up for testing purposes. This no longer works on JDK 17, because those classes aren't exposed. We add this (test, since it's a module that's only used for testing) dependency on bouncycastle, which netty will automatically use instead of the JDK classes.
@@ -62,7 +71,11 @@ private void assertFieldEquals(Field field, Object actual, Object expectedResult | |||
assertTrue(IOUtils.contentEquals((InputStream) field.get(expectedResult), | |||
(InputStream) field.get(actual))); | |||
} else { | |||
assertReflectionEquals(field.get(expectedResult), field.get(actual)); | |||
Difference difference = CustomComparatorFactory.getComparator() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to reviewer: this fixes an issue where the comparator is using reflection to compare instants (which fails on JDK 17), because our comparator library is old enough that it doesn't support Instant types. (It hasn't been updated since 2017).
0b63ca8
to
354c747
Compare
…loading via SystemSettings. This fixes an issue where the existing environment variable helpers did not work on Java 17, because it relied on reflectivly modifying the environment variable map directly.
db914da
to
e73d387
Compare
e73d387
to
0227012
Compare
SonarCloud Quality Gate failed. |
@@ -108,7 +108,7 @@ private Boolean parseBooleanProperty(String propertyKey, String property) { | |||
* Retrieve an unmodifiable view of all of the properties currently in this profile. | |||
*/ | |||
public Map<String, String> properties() { | |||
return properties; | |||
return Collections.unmodifiableMap(properties); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still require wrapping the input list as unmodifiableMap in builder line number 193 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I didn't see that (and neither did spotbugs).
private static class InstantComparator implements Comparator { | ||
@Override | ||
public boolean canCompare(Object left, Object right) { | ||
return left instanceof Instant || right instanceof Instant; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Query :why isn't it ?
return left instanceof Instant && right instanceof Instant;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the same thought at first. I looked at other comparator implementations and they did ||. It actually makes sense after I thought about it. This comparator knows whether two instants are equal, but it also knows whether one instant is equal to a non-instant, so it makes sense to say it can compare an instant and a non-instant (to return false).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it, thanks 👍
…4bb20707f Pull request: release <- staging/15799bce-3545-419d-8e68-bc74bb20707f
The following changes were required:
-XX:+AllowRedefinitionToAddDeleteMethods
enabled, because blockhound requires it for Java 13+: OpenJDK 13 requires -XX:+AllowRedefinitionToAddDeleteMethods flag reactor/BlockHound#33