mattjlewis / diozero

Java Device I/O library that is portable across Single Board Computers and microcontrollers. Tested with Raspberry Pi, Odroid C2, BeagleBone Black, Next Thing CHIP, Asus Tinker Board and Arduinos / Pico. Supports GPIO, I2C, SPI as well as Serial communication. Also known to work with Udoo Quad.
https://www.diozero.com
MIT License
261 stars 59 forks source link

NullPointerException in LocalSystemInfo when VERSION is not set in /etc/os-release #105

Closed bwaldvogel closed 1 year ago

bwaldvogel commented 1 year ago

According to the documentation of /etc/os-release, the VERSION field is optional.

Arch Linux apparently does not set this field which causes the following NullPointerException in LocalSystemInfo: https://github.com/mattjlewis/diozero/blob/5c0b697693ac3c5ef0e0118c5896d68d67035a59/diozero-core/src/main/java/com/diozero/sbc/LocalSystemInfo.java#L268

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.replace(java.lang.CharSequence, java.lang.CharSequence)" because the return value of "java.util.Properties.getProperty(String)" is null
        at com.diozero.sbc.LocalSystemInfo.<init>(LocalSystemInfo.java:268)
        at com.diozero.sbc.LocalSystemInfo.getInstance(LocalSystemInfo.java:244)
        at com.diozero.sbc.LocalBoardInfoUtil.initialiseLocalBoardInfo(LocalBoardInfoUtil.java:62)
        at com.diozero.sbc.LocalBoardInfoUtil.lookupLocalBoardInfo(LocalBoardInfoUtil.java:86)
        at com.diozero.util.LibraryLoader.loadSystemUtils(LibraryLoader.java:67)
        […]
bwaldvogel commented 1 year ago

Please see PR https://github.com/mattjlewis/diozero/pull/106 for my suggested fix.

mattjlewis commented 1 year ago

Brilliant - thank you. Will incorporate ASAP.