jena icon indicating copy to clipboard operation
jena copied to clipboard

OntResource (in ontapi.model) is not public

Open kdubb opened this issue 1 month ago • 5 comments

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

kdubb avatar Oct 30 '25 12:10 kdubb

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 avatar Oct 30 '25 13:10 sszuev

@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.

kdubb avatar Oct 30 '25 14:10 kdubb

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.

sszuev avatar Oct 30 '25 15:10 sszuev

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 avatar Oct 30 '25 16:10 kdubb

@kdubb

I could not reproduce

https://github.com/sszuev/jena-ontapi-i3556

sszuev avatar Nov 02 '25 10:11 sszuev