powsybl-core icon indicating copy to clipboard operation
powsybl-core copied to clipboard

[Export] NPE when exporting new extensions to an older XIIDM version

Open sylvlecl opened this issue 2 years ago • 0 comments

  • Do you want to request a feature or report a bug?

Bug

  • What is the current behavior?

The following code throws an NPE:

Network network = IeeeCdfNetworkFactory.create9();
Properties params = new Properties();
params.setProperty(XMLExporter.VERSION, IidmXmlVersion.V_1_2.toString("."));
Exporters.export("XIIDM", network, params, Paths.get("ieee9.xiidm"));

This is because the SlackTerminal extension did not exist in XIIDM v1.2.

Here is the stack:

java.lang.NullPointerException
	at com.powsybl.iidm.xml.extensions.AbstractVersionableNetworkExtensionXmlSerializer.getVersion(AbstractVersionableNetworkExtensionXmlSerializer.java:82)
	at com.powsybl.iidm.xml.NetworkXml.lambda$getNamespaceUri$3(NetworkXml.java:208)
	at java.base/java.util.Optional.orElseGet(Optional.java:369)
	at com.powsybl.iidm.xml.NetworkXml.getNamespaceUri(NetworkXml.java:208)
	at com.powsybl.iidm.xml.NetworkXml.getNamespaceUri(NetworkXml.java:197)
	at com.powsybl.iidm.xml.NetworkXml.writeExtensionNamespaces(NetworkXml.java:137)
	at com.powsybl.iidm.xml.NetworkXml.initializeWriter(NetworkXml.java:253)
	at com.powsybl.iidm.xml.NetworkXml.write(NetworkXml.java:338)
  • What is the expected behavior?

The export should either throw an explicit exception, so that the user can for example remove the extension, or skip the extension export. The choice between the 2 behaviours could be an export option.

  • What is the motivation / use case for changing the behavior?

The situation occurred when using powsybl-dynaflow, which tries to export to XIIDM v1.2.

sylvlecl avatar Apr 26 '22 14:04 sylvlecl