[rustjava-unsupported-charset-exception] Throw UnsupportedEncodingException instead of panicking on unknown charsets - #5
Merged
Conversation
…wn charsets
An unsupported charset name — pure user input from Java code — hit
unimplemented!() in String.getBytes(charset), new String(byte[], charset)
and InputStreamReader.read(), killing the host process. "hi".getBytes("UTF-16")
was enough to trap the JVM.
- Add java.io.UnsupportedEncodingException (extends java.io.IOException),
registered in the class loader; message carries the offending charset name.
- Extract the charset tables shared by java.lang.String and
java.io.InputStreamReader into java_runtime::charset::Charset so both
paths support the same set — ISO-8859-1/US-ASCII (and aliases) now work
through InputStreamReader instead of only UTF-8/EUC-KR.
- Fix System.setProperty descriptor to the JDK signature
(...)Ljava/lang/String; (was Object), including the jvm bootstrap caller —
javac-compiled code failed with NoSuchMethodError on the old descriptor.
- Add Throwable.getMessage().
- Tests: Rust unit tests for all three throw paths + ISO-8859-1 reader path,
and test_data/UnsupportedCharset fixture proving Java try/catch catches it.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…-charset-exception Resolve STATE.md/REPORT.md add/add conflicts by adopting the superset: all task entries kept, classfile task marked merged at main 549b9eb. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
STATE.md superset resolution; REPORT.md auto-merged. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…arset-exception STATE.md/REPORT.md superset resolution. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Aug 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
java.io.UnsupportedEncodingException(parentjava.io.IOException), following the existing exception-class conventions (eof_exceptionetc.), registered inloader.rs.unimplemented!()charset panics —Stringdecode/encode (string.rs:787/:797) andInputStreamReader.read()(input_stream_reader.rs:115) — into thrownUnsupportedEncodingExceptionwith the offending charset name as the message.java_runtime::charset::Charset(UTF-8 / EUC-KR family / ISO-8859-1 / US-ASCII + aliases).InputStreamReaderpreviously accepted only literalUTF-8/EUC-KR, soSystem.setProperty("file.encoding", "ISO-8859-1")panicked every subsequentread(). No decoder logic was duplicated: the reader's incremental path wraps the same tables (encoding_rsdecoders + byte→char for the single-byte sets).Necessary side fixes
System.setPropertywas declared(...)Ljava/lang/Object;but the JDK signature returnsString— javac-compiled fixtures failed withNoSuchMethodError. Fixed the proto and the jvm bootstrap caller (jvm/src/jvm.rs).Properties.setPropertycorrectly staysObject.Throwable.getMessage()(was missing entirely), needed to verify the exception message from Java code.Evidence
unimplemented!()process panics (not implemented: unsupported charset: UTF-16/Shift_JIS).is_instancechecks confirmUnsupportedEncodingExceptionandIOExceptionin the hierarchy, andgetMessage()returns the charset name.test_data/UnsupportedCharset(javac--release 21, no invokedynamic/StringBuilder) proves Java-sidetry { … } catch (UnsupportedEncodingException e)actually catches forgetBytes("UTF-16"),new String(bytes, "Shift_JIS"), and thefile.encoding=UTF-16reader path — and thatfile.encoding=ISO-8859-1now readsaébcorrectly.cargo test --allfully green (124 java_runtime tests + all fixtures),cargo fmt --check,cargo clippy --alland--target wasm32-unknown-unknownwith-D warningsclean.Non-goals (per ticket)
read(), so multibyte sequences split across buffer boundaries can be lost for EUC-KR.🤖 Generated with Claude Code