Skip to content

Calling Java constructors are not considered interop #2774

@lassemaatta

Description

@lassemaatta
  • I have read the Clojure etiquette and will respect it when communicating on this platform.

version

clj-kondo v2026.01.19

platform

Native binary, Linux AMD64.

editor

Command line.

problem

Calling a Java class constructor is not considered as interop wrt. the :warn-on-reflection linter.

repro

Happy path, interop is detected due to (Date/from bar).

echo '(ns foo (:import [java.util Date])) (def bar [])  (Date/from bar)' | clj-kondo --config '{:linters {:warn-on-reflection {:level :warning}}}' --repro  --debug  --lint -
[clj-kondo] Linting file: <stdin>
<stdin>:1:51: warning: Var *warn-on-reflection* is not set in this namespace.
linting took 3ms, errors: 0, warnings: 1

Sad path, interop is not detected even though we call (Date. bar).

echo '(ns foo (:import [java.util Date])) (def bar [])  (Date. bar)' | clj-kondo --config '{:linters {:warn-on-reflection {:level :warning}}}' --repro  --debug  --lint - 
[clj-kondo] Linting file: <stdin>
linting took 6ms, errors: 0, warnings: 0

config

{:linters {:warn-on-reflection {:level :warning}}}

expected behavior

echo '(ns foo (:import [java.util Date])) (def bar [])  (Date. bar)' | clj-kondo --config '{:linters {:warn-on-reflection {:level :warning}}}' --repro  --debug  --lint - 
[clj-kondo] Linting file: <stdin>
<stdin>:1:51: warning: Var *warn-on-reflection* is not set in this namespace.
linting took 3ms, errors: 0, warnings: 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    High priority (next release)

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions