eclipse-efx / efxclipse-rt

Eclipse Public License 1.0
28 stars 29 forks source link

NPE in JavaModuleLayerModification #394

Open eliasvasylenko opened 4 years ago

eliasvasylenko commented 4 years ago

https://github.com/eclipse-efx/efxclipse-rt/blob/cfdb23a65333a59524db1b1a198a3344308418fe/modules/core/org.eclipse.fx.osgi/src/main/java/org/eclipse/fx/osgi/fxloader/jpms/JavaModuleLayerModification.java#L125

This causes null elements to be included in the stream, which causes the following findFirst to fail with an NPE. Instead of .map(l -> l.findModule(n).orElse(null)) it should probably be something like flatMap(l -> l.findModule(n).stream()). Or if you're targeting earlier versions of Java where that's not in the API, a more awkward map(l -> l.findModule(n)).filter(Optional::isPresent).map(Optional::get).

If the result is is null this indicates an error anyway ... but the NPE prevents the proper exception from being thrown a few lines later with all the relevant information, so it obscures the cause of the problem.

The same mistake appears on lines 91 and 158.

tomsontom commented 4 years ago

Would you mind providing a PR