NullPointerException in upgradetool

Hello all,

I was trying to upgrade from 3.4 to 4.0 using apt. However, during the upgrade, I received lots of warnings and a NullPointerException from the upgradetool.

Can anyone help?

Here is the relevant log:

[openHAB] Running JSON Database upgrade tool (${OPENHAB_RUNTIME}/bin/upgradetool.jar).
[main] INFO org.openhab.core.tools.internal.Upgrader - Copying item unit from state description to metadata in database ‘/var/lib/openhab/jsondb/org.openhab.core.items.Item.json’
[main] WARN org.openhab.core.tools.internal.Upgrader - Hzg_PelletsTRL: Could not determine if channel ‘tacmi:cmiSchema:2d23e725:HzgPelletsRL’ sets a state description. Check if you need to set unit metadata.
[main] WARN org.openhab.core.tools.internal.Upgrader - Hzg_PelletsTRL: State description contains unit place-holder ‘%unit%’, check if ‘unit’ metadata is needed!
[main] WARN org.openhab.core.tools.internal.Upgrader - OpenDTU_HM600_Efficiency: Could not determine if channel ‘mqtt:homeassistant_114184012408:cf0e3c95:OpenDTU:114184012408_5Fch0_5FEfficiency#sensor’ sets a state description. Check if you need to set unit metadata.
[main] WARN org.openhab.core.tools.internal.Upgrader - Internet_Pingzeit: Could not determine if channel ‘network:pingdevice:1feaed620f:latency’ sets a state description. Check if you need to set unit metadata.
[main] WARN org.openhab.core.tools.internal.Upgrader - HzgEVISoll: Could not determine if channel ‘tacmi:cmiSchema:2d23e725:HzgEVISollTemp’ sets a state description. Check if you need to set unit metadata.
[main] WARN org.openhab.core.tools.internal.Upgrader - HzgEVISoll: State description contains unit place-holder ‘%unit%’, check if ‘unit’ metadata is needed!
[main] WARN org.openhab.core.tools.internal.Upgrader - LatencyIPhone: Could not determine if channel ‘network:pingdevice:192_168_0_7:latency’ sets a state description. Check if you need to set unit metadata.
[main] WARN org.openhab.core.tools.internal.Upgrader - Hzg_EVI_VL: Could not determine if channel ‘tacmi:cmiSchema:2d23e725:HzgEVIVL’ sets a state description. Check if you need to set unit metadata.
[main] WARN org.openhab.core.tools.internal.Upgrader - Hzg_EVI_VL: State description contains unit place-holder ‘%unit%’, check if ‘unit’ metadata is needed!
[main] WARN org.openhab.core.tools.internal.Upgrader - RouterOG_Pingzeit: Could not determine if channel ‘network:pingdevice:192_168_0_3:latency’ sets a state description. Check if you need to set unit metadata.
[main] WARN org.openhab.core.tools.internal.Upgrader - Hzg_T_aussen: Could not determine if channel ‘tacmi:cmiSchema:2d23e725:HzgTAussen’ sets a state description. Check if you need to set unit metadata.
[main] WARN org.openhab.core.tools.internal.Upgrader - Hzg_T_aussen: State description contains unit place-holder ‘%unit%’, check if ‘unit’ metadata is needed!
[main] WARN org.openhab.core.tools.internal.Upgrader - LatencyGalaxyS10Zt: Could not determine if channel ‘network:pingdevice:192_168_192_178:latency’ sets a state description. Check if you need to set unit metadata.[main] WARN org.openhab.core.tools.internal.Upgrader - LatencyGalaxyS10: Could not determine if channel ‘network:pingdevice:192_168_0_8:latency’ sets a state description. Check if you need to set unit metadata.
[main] WARN org.openhab.core.tools.internal.Upgrader - Shelly_HT_20_Temperatur: Could not determine if channel ‘shelly:shellyht:8c60c2e5ee:sensors#temperature’ sets a state description. Check if you need to set unit metadata.
[main] WARN org.openhab.core.tools.internal.Upgrader - Hzg_T_Puffer_oben: Could not determine if channel ‘tacmi:cmiSchema:2d23e725:HzgTPufferOben’ sets a state description. Check if you need to set unit metadata.
[main] WARN org.openhab.core.tools.internal.Upgrader - Hzg_T_Puffer_oben: State description contains unit place-holder ‘%unit%’, check if ‘unit’ metadata is needed!
Exception in thread “main” java.lang.NullPointerException
at java.base/java.util.Objects.requireNonNull(Objects.java:209)
at java.base/java.util.Optional.of(Optional.java:113)
at java.base/java.util.stream.FindOps$FindSink$OfRef.get(FindOps.java:194)
at java.base/java.util.stream.FindOps$FindSink$OfRef.get(FindOps.java:191)
at java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:647)
at org.openhab.core.tools.internal.Upgrader.lambda$0(Upgrader.java:136)
at java.base/java.util.concurrent.ConcurrentHashMap$KeySetView.forEach(ConcurrentHashMap.java:4706)
at org.openhab.core.tools.internal.Upgrader.itemCopyUnitToMetadata(Upgrader.java:115)
at org.openhab.core.tools.UpgradeTool.main(UpgradeTool.java:79)

Must be something with my Items and the links to their corresponding channels. The last line of this code within the upgrade tool is failing at findFirst (see stack trace in original post):

        itemStorage.getKeys().forEach(itemName -> {
            ManagedItemProvider.PersistedItem item = itemStorage.get(itemName);
            if (item != null && item.itemType.startsWith("Number:")) {
                if (metadataStorage.containsKey(NumberItem.UNIT_METADATA_NAMESPACE + ":" + itemName)) {
                    logger.debug("{}: Already contains a 'unit' metadata, skipping it", itemName);
                } else {
                    String unit = null;
                    if (!noLink) {
                        List<ItemChannelLink> links = linkStorage.getValues().stream().map(Objects::requireNonNull)
                                .filter(link -> itemName.equals(link.getItemName())).toList();
                        // check if we can find the channel for these links
                        for (ItemChannelLink link : links) {
                            ThingDTO thing = thingStorage.get(link.getLinkedUID().getThingUID().toString());
                            if (thing == null) {
                                logger.info(
                                        "{}: Could not find thing for channel '{}'. Check if you need to set unit metadata.",
                                        itemName, link.getLinkedUID());
                                continue;
                            }
                            String channelTypeUID = thing.channels.stream()
                                    .filter(channel -> link.getLinkedUID().toString().equals(channel.uid))
                                    .map(channel -> channel.channelTypeUID).findFirst().orElse(null);

It seems like, for one item, a link and a thing is found but no channel inside the thing matching the link. Does this make sense? Is there any chance to find out which item is causing the problem?

It is likely to be a cause, can you look for orphaned links? Likely one of your links leads to a non-existent channel. Such situations might be a result of typo but also earlier upgrades which changed channel definitions.