[Note: question basically re-edited after a lot of playing around]
In Java, you have Charset, defining a character encoding. From a Charset, you can obtain two objects:
- a
CharsetEncoder, to turn acharsequence into abytesequence; - a
CharsetDecoder, to turn abytesequence into acharsequence.
Both of these classes have the following methods defined: .onUnmappableCharacter() and .onMalformedInput(). If you tell them for each of these to CodingErrorAction.REPORT they will throw either of these two exceptions: UnmappableCharacterException and MalformedInputException.
With a CharsetEncoder, I am able to generate both of them:
- feed it with a
CharBuffercontaining two high surrogates following one another -->MalformedInputException; - feed it with a
CharBuffercontaining achar(orcharsequence) which the encoding cannot represent:UnmappableCharacterException.
With a CharsetDecoder:
- feed it with an illegal byte sequence:
MalformedInputException-- easy to do; UnmappableCharacterException--> how?
In spite of all my research, I just couldn't do it.
All of this in spite of having played a lot with CharsetDecoder. I could find no combination of Charset and byte sequence able to generare this error...
Is there any at all?