I hit this with Google’s [mug](
https://github.com/google/mug) library. The [format method](
https://google.github.io/mug/apidocs/com/google/mu/util/StringFormat.html#format(java.lang.Object,java.lang.Object)) is declared as public final on AbstractStringFormat, which is package-private. StringFormat is public and [inherits](
https://github.com/google/mug/blob/master/mug/src/main/java/com/google/mu/util/StringFormat.java#L86) it.
In Java this works fine — javac emits invokevirtual on the public subclass. In Clojure, all three interop paths fail:
1. *Type-hinted call* `(.format ^StringFormat fmt "a" "b")` -> No matching method format found taking 2 args
2. *Method reference* `^[Object Object] StringFormat/.format` -> IllegalAccessError: failed to access class AbstractStringFormat
3. *No type hint (reflection)* `(.format fmt "a" "b")` -> same as #1
`java.lang.reflect.Method` works fine — `StringFormat.class.getMethod("format", Object, Object)` finds and invokes it without issues.
This looks like [CLJ-1243](
https://clojure.atlassian.net/browse/CLJ-1243) (open since 2013).
#!/bin/sh
#_(
DEPS='{:deps {com.google.mug/mug {:mvn/version "9.9.9"}}}'
exec clojure -Sdeps "$DEPS" -M "$0" "$@"
)
;;
https://clojure.atlassian.net/browse/CLJ-1243
(import '(com.google.mu.util StringFormat))
(def fmt (StringFormat. "{a}/{b}"))
(println "=== 1 ===")
(try
(eval '(.format ^StringFormat fmt "a" "b"))
(catch Throwable e
(println (str " " (.getClass e) ": " (.getMessage e)))))
(println "=== 2 ===")
(try
(eval '(let [f ^[Object Object] StringFormat/.format]
(f fmt "a" "b")))
(catch Throwable e
(println (str " " (.getClass e) ": " (.getMessage (or (.getCause e) e))))))
(println)
(println "=== 3 ===")
(try
(let [result (.format fmt "a" "b")]
(println (str " result: " result)))
(catch Throwable e
(println (str " " (.getClass e) ": " (.getMessage e)))))
(println)
(println "=== 4 ===")
(let [m (-> StringFormat (.getMethod "format" (into-array Class [Object Object])))]
(.setAccessible m true)
(println (str " result: " (.invoke m fmt (object-array ["a" "b"])))))