Skip to content

[LOG4J2-2561] JEP223 version detection fix for JDK 9 and up#260

Merged
rgoers merged 6 commits intoapache:masterfrom
ulrichenslin:JEP223-java-version-fix
May 13, 2019
Merged

[LOG4J2-2561] JEP223 version detection fix for JDK 9 and up#260
rgoers merged 6 commits intoapache:masterfrom
ulrichenslin:JEP223-java-version-fix

Conversation

@ulrichenslin
Copy link
Contributor

Fix version detection for JDK 9 and up

@jvz
Copy link
Member

jvz commented Mar 1, 2019

Can you add a jira issue for this as well? https://issues.apache.org/jira/browse/LOG4J2

@ulrichenslin ulrichenslin changed the title JEP223 version detection fix for JDK 9 and up [LOG4J2-2561] JEP223 version detection fix for JDK 9 and up Mar 2, 2019
@ulrichenslin
Copy link
Contributor Author

Jira LOG4J2-2561 added for this PR.

Copy link
Contributor

@remkop remkop left a comment

Choose a reason for hiding this comment

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

Looks ok to me. Do we have any unit tests for this, and if so, can we add a test for post-Java 9 version strings? If not, can we add some tests? (Of course making sure we reset the java.version property to its original value after the test or if the test fails.)

@ulrichenslin
Copy link
Contributor Author

Added test for the detection testing.

@remkop Thanks for the advise on reseting the java.version. I missed that in my initial test.

@remkop
Copy link
Contributor

remkop commented Mar 2, 2019

update: looking at this on my phone, I missed that the PR also includes a test. Looks good to me.

@remkop
Copy link
Contributor

remkop commented Mar 2, 2019

Oh, you just added that? Ok, thanks!

@@ -134,7 +134,13 @@ private static boolean isPreJava8() {
final String version = System.getProperty("java.version");
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make this method delegate to a package-private static boolean isPreJava8(String javaVersion) which we can invoke directly from the test? The reflective method is likely to cause failures if we refactor this code in the future, and setting the java.version system property may have other consequences which I'd prefer to avoid.

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 agree, but wanted to make the code change as small as possible, since it is a very minor change.

If we want to be more adventures, we should move the org.apache.logging.log4j.util.Constants#getMajorVersion to core, and just have everything call that. Then the version detection is centralised and can we can test it as a public method.

How to you advise we move forward on this.

Copy link
Member

@rgoers rgoers Mar 2, 2019

Choose a reason for hiding this comment

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

Personally, I dislike checking for versions. I much prefer checking for features. But seeing that this was already implemented I wouldn't expect you to change that.

I am a bit confused by your question though. It looks like Constants has a getMajorVersion method that has the same problem. I would recommend you just fix that and then have AbstractStringLayout reference Constants.JAVA_MAJOR_VERSION. I don't know why you would need to move it from the API to core. If you want to make it able to be unit testable create a new method in Constants that is package private called getMajorVersion(String version) and then have getMajorVersion just be return getMajorVersion(System.getProperty("java.version");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please see updated PR. This is a cleaner implementation.

ulrichenslin added 2 commits March 4, 2019 08:22
Version testing moved to org.apache.logging.log4j.util.ConstantsTest.testJdkVersionDetection
Copy link
Contributor

@carterkozak carterkozak left a comment

Choose a reason for hiding this comment

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

This implementation looks a lot cleaner, thank you!

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.charset.Charset;
import java.util.Properties;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please fix the unused imports in this file?

public class ConstantsTest {

@Test
public void testJdkVersionDetection() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: No need to declare these exception types now that we're calling getMajorVersion directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code has been cleaned up.

@ulrichenslin
Copy link
Contributor Author

The tests on the CI is failing, but the failures are not related to the changes made in this PR.

How do we move forward?

@ulrichenslin
Copy link
Contributor Author

@jvz Thanks for approving the PR.

To get this ported to 2.11, do I just create another PR with the same change on a 'release-2.x' branch, with the same Jira number?

@jvz
Copy link
Member

jvz commented Mar 15, 2019

That's one simple way to do it. I don't recall if I've merged any backported commits myself, though many of the other developers here will merge a commit to both branches concurrently.

As for merging, if anyone else wants to do so, feel free. I'm out of town right now and won't have a chance to merge everything for a few more days.

@rgoers
Copy link
Member

rgoers commented Mar 15, 2019

I'd appreciate a new PR. I have tried various options like cherry picking but never had much luck. I usually end up doing it by hand.

@ulrichenslin
Copy link
Contributor Author

@rgoers @jvz
New for release 2 PR on : #262

@rgoers rgoers merged commit 502f9fc into apache:master May 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants