monarch-initiative / phenol

phenol: Phenotype ontology library
https://phenol.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
23 stars 4 forks source link

java.lang.IllegalAccessError - MinimalOntologyLoader #461

Closed pnrobinson closed 4 months ago

pnrobinson commented 8 months ago

I am getting some weird errors from fenominal in an application program:

Exception in thread "main" java.lang.NoSuchMethodError: 'java.lang.Iterable org.monarchinitiative.phenol.ontology.data.MinimalOntology.nonObsoleteTermIds()'
    at org.monarchinitiative.fenominal.core@0.7.11/org.monarchinitiative.fenominal.core.impl.hpo.HpoLoader.loadSimpleHpoTerms(HpoLoader.java:65)
(...)

However, it appears that this method is correct and is used in the latest phenol.

While trying to debug this, I am seeing this error that comes from ReportParseTest in fenominal

java.lang.IllegalAccessError: class org.monarchinitiative.phenol.io.MinimalOntologyLoader (in unnamed module @0x7c417213) cannot access class org.monarchinitiative.phenol.ontology.data.impl.SimpleMinimalOntology (in module org.monarchinitiative.phenol.core) because module org.monarchinitiative.phenol.core does not export org.monarchinitiative.phenol.ontology.data.impl to unnamed module @0x7c417213

    at org.monarchinitiative.phenol.io.MinimalOntologyLoader.loadOntology(MinimalOntologyLoader.java:95)
    at org.monarchinitiative.phenol.io.MinimalOntologyLoader.loadOntology(MinimalOntologyLoader.java:63)
    at org.monarchinitiative.phenol.io.MinimalOntologyLoader.loadOntology(MinimalOntologyLoader.java:45)
    at org.monarchinitiative.phenol.io.MinimalOntologyLoader.loadOntology(MinimalOntologyLoader.java:36)
    at org.monarchinitiative.fenominal.core@0.7.12-SNAPSHOT/org.monarchinitiative.fenominal.core.TestResources.hpo(TestResources.java:18)
    at org.monarchinitiative.fenominal.core@0.7.12-SNAPSHOT/org.monarchinitiative.fenominal.core.hpo.ReportParseTest.<clinit>(ReportParseTest.java:33)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

@ielis I am not sure if the module-info files wants to export impl (I am guessing we want to export only interfaces).

ielis commented 7 months ago

I am also getting errors like this at other places and I am not sure why. I must investigate this..

pnrobinson commented 7 months ago

I am trying to get fenominal to work but there are some weird things. Running the tests gives this

HPO = MinimalOntologyLoader.loadOntology(HPO_PATH.toFile());

leads to

java.lang.IllegalAccessError: class org.monarchinitiative.phenol.io.MinimalOntologyLoader 
(in unnamed module @0x7c417213) 
cannot access class org.monarchinitiative.phenol.ontology.data.impl.SimpleMinimalOntology 
(in module org.monarchinitiative.phenol.core) 
because module org.monarchinitiative.phenol.core 
does not export org.monarchinitiative.phenol.ontology.data.impl to unnamed module @0x7c417213

I do not think we want to export the impl package.

ielis commented 7 months ago

This is a weird error. I was not able to replicate it elsewhere.

I created a small modular CLI app ModularCliApp, where phenol worked OK.

The ontology loader works OK, when run from CLI on module path:

java --module-path <module-path> --module <some-module> path/to/hp.json

the above shows the invocation on module path.

So, I do not think this is an issue with phenol, but with the setup elsewhere. I think it is related to unnamed module. So, phenol works OK when called from a proper module, and this issue is raised when used from an unnamed module. To mitigate the issue, we should use phenol from class path if making a module is too big of a task.

pnrobinson commented 4 months ago

OK, closing