#1051259 librxtx-java: SIGSEGV while reading serial port

Package:
librxtx-java
Source:
librxtx-java
Description:
Full Java CommAPI implementation
Submitter:
Petr Mikše
Date:
2023-09-05 12:39:04 UTC
Severity:
normal
#1051259#5
Date:
2023-09-05 12:34:25 UTC
From:
To:
Dear Maintainer,

	I am not able to read a serial port using this library.
	I've this routine to open the port:
    private static RXTXPort open(String portName, int baud) {
	System.out.print("Serial.open " + portName + " at " + Integer.toString(baud) + " Baud\n");
	RXTXPort rxtxPort = null;   // suppose no port is open
	try {
	    CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
	    if (portIdentifier.isCurrentlyOwned()) {
		System.err.print("EWC: Error: " + portName + " is currently in use\n");
	    } else {
		CommPort commPort = portIdentifier.open(BootLoader.class.getName(), 2000);
		if (commPort instanceof RXTXPort) {
		    rxtxPort = (RXTXPort) commPort;
		    rxtxPort.setSerialPortParams(baud, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
		    System.out.print(portName + " open at " + Integer.toString(rxtxPort.getBaudRate()) + " Baud\n");
		    //Test it
		    rxtxPort.getOutputStream().write(255);
		    System.out.print("Writen: 255\n");
		    System.out.print("Read: " + Integer.toString(rxtxPort.getInputStream().read()) + '\n');
		} else {
		    System.err.print("EWC: Error: Only serial ports may be used.\n");
		}
	    }
	} catch (Exception ex) {
	    System.err.println(ex);
	    //ex.printStackTrace();
	}
	return rxtxPort;
    }

	The output is:
Serial.open /dev/ttyS0 at 115200 Baud
/dev/ttyS0 open at 115200 Baud
Writen: 255
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007fd2b4009762, pid=9221, tid=9222
#
# JRE version: OpenJDK Runtime Environment (11.0.20+8) (build 11.0.20+8-post-Debian-1deb11u1)
# Java VM: OpenJDK 64-Bit Server VM (11.0.20+8-post-Debian-1deb11u1, mixed mode, sharing, tiered, compressed oops, g1 gc, linux-amd64)
# Problematic frame:
# C  [librxtxSerial-2.1-7.so+0x7762]  read_byte_array+0x52
#
# Core dump will be written. Default location: Core dumps may be processed with "/lib/systemd/systemd-coredump %P %u %g %s %t 9223372036854775808 %h" (or dumping to /mnt/JESSIE/opt/ewcs/bin/core.9221)
#
# An error report file with more information is saved as:
# /tmp/hs_err_pid9221.log

	If I copy /usr/lib/jni from bullseye to /usr/lib, the output is:
WARNING:  RXTX Version mismatch
        Jar version = RXTX-2.2
        native lib Version = RXTX-2.2pre2
Serial.open /dev/ttyS0 at 115200 Baud
/dev/ttyS0 open at 115200 Baud
Writen: 255
Read: 255

and continues correctly.