Why does ```javax.xml.xpath.XPathFactory.newInstan...
# announcements
v
Why does
Copy code
javax.xml.xpath.XPathFactory.newInstance().newXPath().compile("/").evaluateExpression(null)
give
Copy code
error: unresolved reference: evaluateExpression
javax.xml.xpath.XPathFactory.newInstance().newXPath().compile("/").evaluateExpression(null)
                                                                   ^
when compiling the Kotlin code using Java 11? The IDE has no problem, but if you compile it in a file or execute it in a REPL it says unresolved reference. The method was added in Java 9
z
If this isn’t a kotlin question, you’re probably better off looking on stackoverflow or something.
a
Seems ok in Kotlin Jupyter kernel
Jupyter kernel seems a lot more perfect than scriptings/repl 🤔 You can also pull deps from any maven repo.
And it can run any cell at any time rather than REPL -> writing and then executing if you wanted to run second last you have to copy paste :P
v
This is a pure Kotlin question @Zach Klippenstein (he/him) [MOD] and Goggle didn't help much.
@Animesh Sahu that's not really helpful but thanks. I need to use that in a Gradle plugin and the
.kt
file does not compile, while the IDE is happy. In the REPL it just identically reproduces.
😮 1
a
Can’t reproduce the compile error myself with a tiny project or in the REPL. Works fine to compile with 11 or 15, on Kotlin 1.4.30
v
Hm, me too in fresh project. :-/
Will investigate what is different, thanks for the hint
Hm, in a project with
kotlin("jvm") version "1.4.20"
or
kotlin("jvm") version "1.4.30"
it works perfectly fine. But if I instead use
kotlin-dsl
it fails.
.evaluate(...)
can be found,
.evaluateExpression(...)
not.
Oh my f***ing god. The significant difference is, that there is
<GRADLE_USER_HOME>/caches/6.8.2/generated-gradle-jars/gradle-api-6.8.2.jar
on the class path. This jar contains several non-Gradle classes, including
javax.xml.xpath.XPathFactory
. Obviously this class is preferred over the actual JRE class and is a pre-Java-9 version where the method is missing. I don't know why this is the case and will report it to both, because IntelliJ should also have been intelligent enough to tell that the method is not available. Thanks @araqnid for making me look deeper.
😬 1
😮 1
Or actually it is probably a compiler bug, as at runtime the JRE class wins. You could for example also define a Kotlin class
Copy code
package java.lang

class String {
    fun foo() = println("FOO")
}
then do
Copy code
fun main() {
    ("" as java.lang.String).foo()
}
While IntelliJ will paint the
foo
in red as it looks into the wrong class, it compiles just fine. And then when it runs, it fails with
Copy code
Exception in thread "main" java.lang.NoSuchMethodError: 'void java.lang.String.foo()'
	at FooKt.main(Foo.kt:3)
	at FooKt.main(Foo.kt)
Same problem as I had, but you can do really bad things with that probably.
👀 1