Vampire
02/13/2021, 3:27 AMjavax.xml.xpath.XPathFactory.newInstance().newXPath().compile("/").evaluateExpression(null)
give
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 9Zach Klippenstein (he/him) [MOD]
02/13/2021, 5:38 AMAnimesh Sahu
02/13/2021, 5:52 AMAnimesh Sahu
02/13/2021, 5:54 AMAnimesh Sahu
02/13/2021, 5:55 AMVampire
02/13/2021, 10:22 AMVampire
02/13/2021, 10:24 AM.kt
file does not compile, while the IDE is happy. In the REPL it just identically reproduces.araqnid
02/13/2021, 8:45 PMVampire
02/14/2021, 1:28 AMVampire
02/14/2021, 1:28 AMVampire
02/14/2021, 1:31 AMkotlin("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.Vampire
02/14/2021, 2:35 AM<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.Vampire
02/14/2021, 3:01 AMpackage java.lang
class String {
fun foo() = println("FOO")
}
then do
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
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.Vampire
02/14/2021, 3:37 AM