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

Support for System.getProperty("java.version") #37

Closed
tresf opened this issue Apr 17, 2017 · 1 comment
Closed

Support for System.getProperty("java.version") #37

tresf opened this issue Apr 17, 2017 · 1 comment

Comments

@tresf
Copy link

tresf commented Apr 17, 2017

Java's own internal version scheme is: 1.8.0_121

Version v = Version.valueOf(System.getProperty("java.version"));

However when attempting to parse Java's own version information the following exception is raised.

Caused by: Unexpected character 'ILLEGAL(_)' at position '5', expecting '[HYPHEN, PLUS, EOI]'
	at com.github.zafarkhaja.semver.VersionParser.consumeNextCharacter(VersionParser.java:516)
	at com.github.zafarkhaja.semver.VersionParser.parseValidSemVer(VersionParser.java:259)
	at com.github.zafarkhaja.semver.VersionParser.parseValidSemVer(VersionParser.java:195)
	at com.github.zafarkhaja.semver.Version.valueOf(Version.java:265)

I've tried replacing the underscore with a period and it raises a similar error: Unexpected character 'DOT(.)' at position '5', expecting '[HYPHEN, PLUS, EOI]'

This seems like the most basic use-case inspired by a very simple Oracle version parsing. Am I using the library wrong, or is Oracle's own format not supported by this library?

The use-case is to test for a specific update level inside Java (e.g. u121 vs u141).

@tresf
Copy link
Author

tresf commented Apr 17, 2017

Closing this out since turning Java's version string into a valid SemVer will fix it.

The following snippet will fix Java version parsing...

This will turn 1.8.0_42 to 1.8.0-42 and fix the parsing error...

- Version v = Version.valueOf(System.getProperty("java.version"));
+ Version v = Version.valueOf(System.getProperty("java.version").replaceFirst("_", "-"));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants