Skip to content

Deprecate JdkVersion (for optimistic compatibility with newer JDK generations) [SPR-13312] #17897

Closed
@spring-projects-issues

Description

@spring-projects-issues

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

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions