Replace a class within the Java class library with a custom version

后端 未结 2 777
野趣味
野趣味 2020-12-03 01:14

The class BasicLabelUI in javax/swing/plaf/basic is affected by a confirmed bug. In my application I need functionality provided by the fixed vers

2条回答
  •  醉梦人生
    2020-12-03 02:11

    How can I force my project to favor my included version of the class over the defective class in the installed JDK?

    Simple answer - you can't. At least, not while strictly obeying the constraint that you should use the affected Javs version.

    Assuming that you can identify an appropriate version in the OpenJDK source repos, it is possible to build your own flavor of the Java libraries with a bug patched. However, that won't be real Java. Certainly, it won't qualify as "the affected Java version" that you are constrained to use. (And besides, you are committing yourself to an endless cycle of reapplying your patch to each new patch release of the current version of Java ...)

    It is also possible in theory to put a modified version of some Java standard library class into a JAR and prepend it to the JVM's bootstrap classpath using the -Xbootclasspath command line option. But that is tantamount to changing "the affected Java version" too.

    Doing it by using a Java agent to use a patched version of the class is breaking the rules too. And it is more complicated.


    If you and your customers do decide that tweaking the JVM is an acceptable solution, then doing it via the bootstrap classpath is probably the simplest and cleanest approach. And it is DEFINITELY legal1.

    However, I'd recommend that you find a workaround for the bug until a version of Java 9 with your fix is released.


    1 - Actually, even the build-from-modified-source approach is legal, because the Oracle Binary license does not apply to that. The Binary license is about distributing a modified version of an Oracle binary. The other possible issue is that you may be violating the terms for using the Java trademark(s) if you distribute a version that is incompatible with "true" Java, and call your distro "Java". The solution to that is ... don't call it "Java"!

    However, don't just follow my advice. Ask a lawyer. Better yet, don't do it at all. It is unnecessarily complicated.

提交回复
热议问题