Clojure

Address JDK API deprecations

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: Release 1.10
  • Fix Version/s: Release 1.10
  • Component/s: None
  • Labels:
  • Patch:
    Code
  • Approval:
    Ok

Description

The JDK now has a clearer policy regarding API deprecations. Currently, there are 6 deprecated call sites in Clojure as of Java 11:

# build local self-contained jar (use Java 8 to match current baseline)
mvn -Plocal -Dmaven.test.skip=true package

# run jdeprscan tool to find deprecations (use Java 11 to get furthest report)
jdeprscan --release 11 clojure.jar

class clojure/pprint$translate_param uses deprecated method java/lang/Integer::<init>(Ljava/lang/String;)V 
class clojure/java/browse_ui$open_url_in_swing uses deprecated method java/awt/Window::show()V
class clojure/core$mix_collection_hash uses deprecated method java/lang/Long::<init>(J)V
class clojure/core$hash_ordered_coll uses deprecated method java/lang/Long::<init>(J)V
class clojure/core$hash_unordered_coll uses deprecated method java/lang/Long::<init>(J)V
class clojure/lang/DynamicClassLoader uses deprecated method java/lang/ClassLoader::getPackage(Ljava/lang/String;)Ljava/lang/Package;

The first two occur in clj files, and have clear replacement calls. The patch makes these replacements.

The next three (the Long(long) constructors) are emitted by the compiler via asm's GeneratorAdapter while boxing invokeStatic and invokePrim. The Long constructors were deprecated in JDK9 [1], with the note that Hotspot intrinsifies the preferred call (Long/valueOf). GeneratorAdapter also has a valueOf() method so in the case of long/double returns, this is used instead (and otherwise it falls back to prior behavior).

Addressing all of the above remains compatible with JDK8. The last issue is reported as of JDK 9. It recommends using getDefinedPackage instead, but that method does not exist until JDK 9 and we are using a JDK 8 baseline, so no change was made. (The method still exists through Java 11 and has not been removed.)

Patch: clj-2375-2.patch

  1. CLJ-2375.patch
    11/Jul/18 4:52 PM
    6 kB
    Ghadi Shayban
  2. clj-2375-2.patch
    03/Oct/18 10:30 AM
    3 kB
    Alex Miller

Activity

Hide
Alex Miller added a comment -

Tested open-url-in-swing still works (for browse-ui change):

(require '[clojure.java.browse :refer :all])
(#'clojure.java.browse/open-url-in-swing "https://google.com")

Tested cl-format still works (this invokes the changed code path):

(clojure.pprint/cl-format true "~5d" 1)  ;;=> prints "    1"

Tested these produce the same values are the same before/after:

(hash (vec (range 1000)))
(hash (zipmap (range 1000) (range 1000)))
Show
Alex Miller added a comment - Tested open-url-in-swing still works (for browse-ui change):
(require '[clojure.java.browse :refer :all])
(#'clojure.java.browse/open-url-in-swing "https://google.com")
Tested cl-format still works (this invokes the changed code path):
(clojure.pprint/cl-format true "~5d" 1)  ;;=> prints "    1"
Tested these produce the same values are the same before/after:
(hash (vec (range 1000)))
(hash (zipmap (range 1000) (range 1000)))

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: