OntResource (in ontapi.model) is not public
Version
5.6.0
What happened?
OntResource is not public therefore calling any methods overridden from RDFNode (E.g., OntModel getModel()) results in an IllegalAccessError.
This was experienced when building/running for Java 24/25.
Relevant output and stacktrace
Are you interested in making a pull request?
None
It is a technical super-interface, with package-local visibility. All methods must be accessible from subclasses. For me it works, e.g.:
OntModelFactory.createModel().createOntClass("x").getModel().write(System.out, "ttl")
Can you please provide a code snippet to reproduce the issue? I don't understand what might not work here.
@sszuev Thanks for the response, this appears to be a Kotlin issue.
I've used this pattern before but I don't think I've used/seen it where the inaccessible interface is overriding a public method for covariance. I was calling it from OntProperty to access the model as an OntModel. It does seem dubious (even if it works in Java) unless in Java it's returning a Model and not OntModel; considering the accessing code is not supposed to "see" the OntResource which is declaring the OntModel return via covariance.
I can't reproduce this issue even on kotlin 1.9.23:
fun main() {
val c = OntModelFactory.createModel().createOntClass("x")
val m = c.model
println(m.id)
m.write(System.out, "ttl")
}
as a workaround we could copy-paste the content of the class into OntObject & OntResource.
or, indeed, make OntResource public and create corresponding factory (to allow .as(OntResource.class) syntax).
or maybe just make public and document that it is a "special resource" with no support of jena-polymorphism, because there is already OntObject with the same functionality.
These ways are not perfect to me.
For reproduction sake, I'm using Kotlin 2.2.20, targeting JDK 24 (running on 24 or 25) with Kotlin 2.2 language mode. Additionally, not that it should matter but the failure I saw was from accessing OntProperty.model.
Here's the Gradle config block for Kotlin:
kotlin {
jvmToolchain(24)
compilerOptions {
languageVersion = KotlinVersion.KOTLIN_2_2
apiVersion = KotlinVersion.KOTLIN_2_2
jvmTarget = JvmTarget.JVM_24
javaParameters = true
freeCompilerArgs.add("-Xcontext-parameters")
freeCompilerArgs.add("-Xnested-type-aliases")
}
}
@kdubb
I could not reproduce
https://github.com/sszuev/jena-ontapi-i3556