-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Deprecate JdkVersion (for optimistic compatibility with newer JDK generations) [SPR-13312] #17897
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
Comments
Michał Sobkiewicz commented I forgot about example usage. Here it is: if (JvmVersion.JAVA_1_8.isCompatibleWithRuntime()) {
// ...
} |
Stéphane Nicoll commented I am not sure I understand the link between your issue and #16518. You're not expecting us to recognize a JDK version that a) did not exist when we released that version of the framework and b) does not work at all with said version. What's a point of being able to recognize Java 8 using Spring 2.5 if you can't effectively run a Spring 2.5-based app with Java 8? |
Michał Sobkiewicz commented My point is that nothing should prevent you from running Spring 2.5 with Java 8 or using Spring 4.2 optional features designed for Java 8 with Java 10. a) I'm not expecting you to recognize JDK versions that didn't exist when framework was released. It's rather what you are trying to do. Obviously, you can't create constant for versions that are not yet known (let them be static, enums, whatever). I'm trying to show you that code based on JdkVersion won't work properly on future JVMs, just because it has no constant for future JVMs - it can't - and that's the point! Instead of comparing constants, you should test if one of known versions is compatible with the current runtime - but without creating constant for current. That's all you need - I suppose - and JvmVersion does exactly and only that (it has just one method, it can't be simpler). If you really need more, please try to develop something similar to ComparableVersion from maven. b) If it doesn't work because you use language features that was not present at the time of releasing framework in that framework (enums, try-withresources, lambdas, modules, value-based classes, ...), it's ok. I don't mind. You can't do anything with that. But if it breaks because something like bug or bad design, that's another story. Suppose Spring 4.2 is binary compatible with Java 10. It's likely to be true as Java versions are expected to be binary backwards-compatible. Now look at:
By the way, another source of potential bugs is following assumption: It's not about Spring 2.5 really. We are switching to String 3.2.9 or Spring 4.2 anyway. It's about reliable, error-free code. |
Juergen Hoeller commented In the end, As a consequence, let me repurpose this issue towards deprecating Juergen |
Michał Sobkiewicz commented Makes sense. I'll check 4.2.1 then, just to sleep well, as soon as it's released. |
Michał Sobkiewicz opened SPR-13312 and commented
After hitting something similar to #16518 (with legacy code using Spring 2.5), I'd like to suggest some refactoring. There will be similar bugs in the future because of how org.springframework.core.JdkVersion is designed. It breaks when you use JVM which was not included in constants.
If full version information is needed at runtime (which I doubt), see
org.apache.maven.artifact.versioning.ComparableVersion as an example of how to handle versioning properly. However, if checking runtime compatibility is the only thing needed (which is the case, I think), it can be done in a much simpler way.
I attached my own helper, JvmVersion. It provides everything that is necessary "to allow for automatically adapting to the present platform's capabilities". I know that there were no enums before Java 5, but, well, Java 5 is over 10 years old, Spring 4 requires Java 6. As you can see, JvmVersion delegates to Package#isCompatibleWith(String) - so you don't have to handle system properties or dot notation manually - it just works. You could refactor existing code and deprecate JdkVersion to avoid new bugs. It would make me very proud of myself ;-)
Sorry for not creating pull request - it's just one file... Hope you will find it useful anyway.
PS. See standardReflectionAvailable property in org.springframework.core.DefaultParameterNameDiscoverer (Spring 4.2) as an example of what can go wrong.
Affects: 4.2 GA
Attachments:
Issue Links:
Referenced from: commits acb44f9, e0f012f, 27e9db8, 5e9a968, bec3b0f
The text was updated successfully, but these errors were encountered: