-
Bug
-
Resolution: Done
-
Major
-
None
-
None
-
2020 Week 52-03 (from Dec 21)
-
Undefined
-
NEW
-
NEW
When a fellow Red Hatter tried OptaPlanner from source with Intellij Community Edition, he ran into the NPE exception below when running TspApp.
This line in GenericJaxbIO throws an NPE (actually the newSchema call throws it):
return schemaFactory.newSchema(GenericJaxbIO.class.getResource(nonNullSchemaResource));
On closer inspection, it turns out that target/classes doesn't contain the XSD file (probably because the JAXB plugin didn't run in IntelliJ Community?), so getResource() returns null.
Note that I don't expect to see this issue with anyone using optaplanner from Maven Central. Only when they run from source.
Proposal A):
Fail fast if the getResource() returns null. The fail fast message should talk about the fact that the XSD file isn't there and "\nMaybe" the JAXB plugin didn't run.
Exception in thread "main" java.lang.NullPointerException
at java.xml/javax.xml.validation.SchemaFactory.newSchema(SchemaFactory.java:701)
at org.optaplanner.core.impl.io.jaxb.GenericJaxbIO.readSchemaResource(GenericJaxbIO.java:134)
at org.optaplanner.core.impl.io.jaxb.GenericJaxbIO.readAndValidate(GenericJaxbIO.java:117)
at org.optaplanner.core.impl.io.jaxb.SolverConfigIO.read(SolverConfigIO.java:34)
at org.optaplanner.core.config.solver.SolverConfig.createFromXmlReader(SolverConfig.java:203)
at org.optaplanner.core.config.solver.SolverConfig.createFromXmlInputStream(SolverConfig.java:177)
at org.optaplanner.core.config.solver.SolverConfig.createFromXmlResource(SolverConfig.java:117)
at org.optaplanner.core.config.solver.SolverConfig.createFromXmlResource(SolverConfig.java:92)
at org.optaplanner.core.api.solver.SolverFactory.createFromXmlResource(SolverFactory.java:55)
at org.optaplanner.examples.common.app.CommonApp.createSolverFactory(CommonApp.java:138)
at org.optaplanner.examples.common.app.CommonApp.createSolutionBusiness(CommonApp.java:127)
at org.optaplanner.examples.common.app.CommonApp.init(CommonApp.java:116)
at org.optaplanner.examples.common.app.CommonApp.init(CommonApp.java:112)
at org.optaplanner.examples.tsp.app.TspApp.main(TspApp.java:38)