diff --git a/README.md b/README.md
index 3a9996ac7..d486b836f 100644
--- a/README.md
+++ b/README.md
@@ -8,7 +8,7 @@ A small, single Java library for working with serial ports across various system
io.github.java-native
jssc
- 2.10.0
+ 2.10.1
```
* or Gradle (KTS)
@@ -17,7 +17,7 @@ repositories {
mavenCentral()
}
dependencies {
- implementation("io.github.java-native:jssc:2.10.0")
+ implementation("io.github.java-native:jssc:2.10.1")
}
```
* or Gradle (Groovy)
@@ -26,7 +26,7 @@ repositories {
mavenCentral()
}
dependencies {
- implementation 'io.github.java-native:jssc:2.10.0'
+ implementation 'io.github.java-native:jssc:2.10.1'
}
```
* [API code examples](../../wiki/examples)
diff --git a/pom.xml b/pom.xml
index 0b3466aac..7b80d3a44 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
io.github.java-native
jssc
- 2.10.1
+ 2.10.2
Java Simple Serial Connector
@@ -32,7 +32,7 @@
scm:git:https://github.com/java-native/jssc.git
scm:git:git@github.com:java-native/jssc.git
https://github.com/java-native/jssc
- v2.10.1
+ v2.10.2
diff --git a/src/main/cpp/_nix_based/jssc.cpp b/src/main/cpp/_nix_based/jssc.cpp
index bcc814784..cab25db09 100644
--- a/src/main/cpp/_nix_based/jssc.cpp
+++ b/src/main/cpp/_nix_based/jssc.cpp
@@ -662,12 +662,15 @@ JNIEXPORT jbyteArray JNICALL Java_jssc_SerialNativeInterface_readBytes
jbyteArray returnArray = NULL;
int byteRemains = byteCount;
- if( byteCount <= 0 ){
+ if( byteCount < 0 ){
char emsg[64]; emsg[0] = '\0';
- snprintf(emsg, sizeof emsg, "byteCount %d. Expected range: 1..2147483647", byteCount);
+ snprintf(emsg, sizeof emsg, "byteCount %d. Expected range: 0..2147483647", byteCount);
jclass exClz = env->FindClass("java/lang/IllegalArgumentException");
if( exClz ) env->ThrowNew(exClz, emsg);
returnArray = NULL; goto Finally;
+ }else if( byteCount == 0 ){
+ returnArray = env->NewByteArray(0);
+ goto Finally;
}
lpBuffer = (jbyte*)malloc(byteCount*sizeof*lpBuffer);
diff --git a/src/main/cpp/windows/jssc.cpp b/src/main/cpp/windows/jssc.cpp
index 595873c1c..0f08718f0 100644
--- a/src/main/cpp/windows/jssc.cpp
+++ b/src/main/cpp/windows/jssc.cpp
@@ -281,12 +281,15 @@ JNIEXPORT jbyteArray JNICALL Java_jssc_SerialNativeInterface_readBytes
jbyte *lpBuffer = NULL;
OVERLAPPED *overlapped = NULL;
- if( byteCount <= 0 ){
+ if( byteCount < 0 ){
char emsg[64]; emsg[0] = '\0';
- snprintf(emsg, sizeof emsg, "byteCount %d. Expected range: 1..2147483647", byteCount);
+ snprintf(emsg, sizeof emsg, "byteCount %d. Expected range: 0..2147483647", byteCount);
jclass exClz = env->FindClass("java/lang/IllegalArgumentException");
if( exClz ) env->ThrowNew(exClz, emsg);
returnArray = NULL; goto Finally;
+ }else if( byteCount == 0 ){
+ returnArray = env->NewByteArray(0);
+ goto Finally;
}
returnArray = env->NewByteArray(byteCount);
diff --git a/src/main/java/jssc/SerialNativeInterface.java b/src/main/java/jssc/SerialNativeInterface.java
index 8f2b59156..091dc3848 100644
--- a/src/main/java/jssc/SerialNativeInterface.java
+++ b/src/main/java/jssc/SerialNativeInterface.java
@@ -34,7 +34,7 @@
*/
public class SerialNativeInterface {
- private static final String libVersion = "2.10.1";
+ private static final String libVersion = "2.10.2";
/** Linux **/
public static final int OS_LINUX = 0;
diff --git a/src/main/resources-precompiled/natives/linux_32/libjssc.so b/src/main/resources-precompiled/natives/linux_32/libjssc.so
index 26f53f638..365bf14f3 100755
Binary files a/src/main/resources-precompiled/natives/linux_32/libjssc.so and b/src/main/resources-precompiled/natives/linux_32/libjssc.so differ
diff --git a/src/main/resources-precompiled/natives/linux_64/libjssc.so b/src/main/resources-precompiled/natives/linux_64/libjssc.so
index 474a07e6d..e3f8908db 100755
Binary files a/src/main/resources-precompiled/natives/linux_64/libjssc.so and b/src/main/resources-precompiled/natives/linux_64/libjssc.so differ
diff --git a/src/main/resources-precompiled/natives/linux_arm/libjssc.so b/src/main/resources-precompiled/natives/linux_arm/libjssc.so
index f8f57f375..d12d7c7cc 100755
Binary files a/src/main/resources-precompiled/natives/linux_arm/libjssc.so and b/src/main/resources-precompiled/natives/linux_arm/libjssc.so differ
diff --git a/src/main/resources-precompiled/natives/linux_arm64/libjssc.so b/src/main/resources-precompiled/natives/linux_arm64/libjssc.so
index 8ed2da754..07097c05b 100755
Binary files a/src/main/resources-precompiled/natives/linux_arm64/libjssc.so and b/src/main/resources-precompiled/natives/linux_arm64/libjssc.so differ
diff --git a/src/main/resources-precompiled/natives/linux_ppc/libjssc.so b/src/main/resources-precompiled/natives/linux_ppc/libjssc.so
index f03c7fb87..ceff66c5a 100755
Binary files a/src/main/resources-precompiled/natives/linux_ppc/libjssc.so and b/src/main/resources-precompiled/natives/linux_ppc/libjssc.so differ
diff --git a/src/main/resources-precompiled/natives/linux_riscv32/libjssc.so b/src/main/resources-precompiled/natives/linux_riscv32/libjssc.so
index e2eb3def3..fc368917c 100755
Binary files a/src/main/resources-precompiled/natives/linux_riscv32/libjssc.so and b/src/main/resources-precompiled/natives/linux_riscv32/libjssc.so differ
diff --git a/src/main/resources-precompiled/natives/linux_riscv64/libjssc.so b/src/main/resources-precompiled/natives/linux_riscv64/libjssc.so
index 937df20e0..3fbed2315 100755
Binary files a/src/main/resources-precompiled/natives/linux_riscv64/libjssc.so and b/src/main/resources-precompiled/natives/linux_riscv64/libjssc.so differ
diff --git a/src/main/resources-precompiled/natives/osx_64/libjssc.dylib b/src/main/resources-precompiled/natives/osx_64/libjssc.dylib
index f93b9b972..6b8da70c8 100755
Binary files a/src/main/resources-precompiled/natives/osx_64/libjssc.dylib and b/src/main/resources-precompiled/natives/osx_64/libjssc.dylib differ
diff --git a/src/main/resources-precompiled/natives/osx_arm64/libjssc.dylib b/src/main/resources-precompiled/natives/osx_arm64/libjssc.dylib
index 72cd40de7..97085dd5d 100755
Binary files a/src/main/resources-precompiled/natives/osx_arm64/libjssc.dylib and b/src/main/resources-precompiled/natives/osx_arm64/libjssc.dylib differ
diff --git a/src/main/resources-precompiled/natives/windows_32/jssc.dll b/src/main/resources-precompiled/natives/windows_32/jssc.dll
index c2e25875d..8eba63a69 100755
Binary files a/src/main/resources-precompiled/natives/windows_32/jssc.dll and b/src/main/resources-precompiled/natives/windows_32/jssc.dll differ
diff --git a/src/main/resources-precompiled/natives/windows_64/jssc.dll b/src/main/resources-precompiled/natives/windows_64/jssc.dll
index aab778e9c..026c7cdf2 100755
Binary files a/src/main/resources-precompiled/natives/windows_64/jssc.dll and b/src/main/resources-precompiled/natives/windows_64/jssc.dll differ
diff --git a/src/main/resources-precompiled/natives/windows_arm64/jssc.dll b/src/main/resources-precompiled/natives/windows_arm64/jssc.dll
index f72d34299..81386c146 100755
Binary files a/src/main/resources-precompiled/natives/windows_arm64/jssc.dll and b/src/main/resources-precompiled/natives/windows_arm64/jssc.dll differ
diff --git a/src/test/java/jssc/SerialNativeInterfaceTest.java b/src/test/java/jssc/SerialNativeInterfaceTest.java
index a1186c923..91adbbf1e 100644
--- a/src/test/java/jssc/SerialNativeInterfaceTest.java
+++ b/src/test/java/jssc/SerialNativeInterfaceTest.java
@@ -9,6 +9,7 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -110,16 +111,25 @@ public void throwsIfCountNegative() throws Exception {
}
}
+ /**
+ * I think this case should just throw an exception, as trying to read zero
+ * bytes doesn't make much sense to me. But it seems we need to accept a
+ * "read of zero bytes" as a legal case. So jssc will respond with an empty
+ * array, exactly as caller did request.
+ * See also "https://github.com/java-native/jssc/issues/192".
+ *
+ * Update: According to
+ * https://github.com/java-native/jssc/issues/192#issuecomment-2960137775
+ * there seems to exist some other issue related to events, which occasionly
+ * provocates zero-length reads. So as long this other issue exists, jssc
+ * probably should handle zero-length reads, as it seems to cause them
+ * itself. */
@Test
- public void throwsIfCountZero() throws Exception {
+ public void returnsAnEmptyArrayIfCountIsZero() throws Exception {
SerialNativeInterface testTarget = new SerialNativeInterface();
- byte[] ret;
- try{
- ret = testTarget.readBytes(0, 0);
- fail("Where's the exception?");
- }catch( IllegalArgumentException ex ){
- assertTrue(ex.getMessage().contains("0"));
- }
+ byte[] ret = testTarget.readBytes(0, 0);
+ assertNotNull(ret);
+ assertTrue(ret.length == 0);
}
@Test