Skip to content

Map NULL and long C strings to and from String - #84

Merged
dmlloyd merged 1 commit into
smallrye:mainfrom
SiteNetSoft:fix-string-null-and-length
Nov 17, 2026
Merged

dmlloyd merged 1 commit into
smallrye:mainfrom
SiteNetSoft:fix-string-null-and-length

Conversation

@jnbdz

@jnbdz jnbdz commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

A String result or argument now handles NULL and long strings. A NULL const char * result is returned as null; before, the generated code read a C string at address 0 and the JVM crashed with SIGSEGV (getenv of an unset variable). A result is read up to its terminator with reinterpret(Long.MAX_VALUE), as the MemorySegment documentation suggests for strings of unknown length, instead of a 1024-byte segment, which threw IndexOutOfBoundsException: No null terminator found for longer strings. A null String argument is passed as MemorySegment.NULL instead of throwing NullPointerException from allocateFrom, so that parameters which accept NULL (a query, a default value) can be declared as String. Both changes are in StringResultStep and StringArgumentStep in Generator.

StringNullTest calls libc: getenv of an unset variable (crashes the test JVM on main), strcpy of a 5000-character string into a native buffer with the result mapped to String (fails with IndexOutOfBoundsException on main), and setlocale(LC_ALL, null) (fails with NullPointerException on main).

mvn verify on JDK 25 (Linux x86_64): 36 tests, 3 skipped.

A NULL const char * result is returned as null instead of crashing the JVM, a result is read up to its terminator instead of being limited to 1024 bytes, and a null String argument is passed as NULL.
@dmlloyd
dmlloyd merged commit 7e6b6d7 into smallrye:main Nov 17, 2026
4 checks passed
@github-actions github-actions Bot added this to the 1.0 milestone Nov 17, 2026
@jnbdz
jnbdz deleted the fix-string-null-and-length branch November 17, 2026 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

String return values: a NULL return crashes the JVM, and returns longer than 1024 bytes throw; a null String argument throws instead of passing NULL

2 participants