You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Data is silently changed and conversion errors are just ignored.
This lead to corrupt data, it is particularly bad if it goes undetected for a long period of time.
Therefore the default behavior should make the user aware of the problem.
Newer introduced API (JDK 11) like java.nio.file.Files.readString(..) and java.nio.file.Files.writeString(..) also use the reporting error approach.
An alternative would be to make ReaderInputStream public and allow to pass a Reader and a CharsetEncoder.
The encoder can be created by the caller via charset.newEncoder() easily and configured according the intended use case.
This was requested in #5376.
Example
Nocodeneedstobechangedbeforehand. It's just about reporting a problem.
Current Behavior
Encoding errors are silently ignored and lead to corrupt text files.
Desired Behavior
Encoding errors should raise an exception and make errors visible, subsequently the code or data in question gets fixed.
Concrete Use Cases
We process texts from customers that use German and Cyrillic letters and it is crucial that the content remains intact when decoding / encoding is used.
Passing a CharsetEncoder allows you to define the behavior on malformed input and on unmappable characters. The existing Charset is actually an encoder factory.
API(s)
How do you want it to be improved?
Use the default error action for malformed input and unmappable characters when creating the encoder by removing following lines:
and update the corr. Javadoc.
Why do we need it to be improved?
Data is silently changed and conversion errors are just ignored.
This lead to corrupt data, it is particularly bad if it goes undetected for a long period of time.
Therefore the default behavior should make the user aware of the problem.
Newer introduced API (JDK 11) like java.nio.file.Files.readString(..) and java.nio.file.Files.writeString(..) also use the reporting error approach.
An alternative would be to make ReaderInputStream public and allow to pass a Reader and a CharsetEncoder.
The encoder can be created by the caller via
charset.newEncoder()
easily and configured according the intended use case.This was requested in #5376.
Example
Current Behavior
Encoding errors are silently ignored and lead to corrupt text files.
Desired Behavior
Encoding errors should raise an exception and make errors visible, subsequently the code or data in question gets fixed.
Concrete Use Cases
We process texts from customers that use German and Cyrillic letters and it is crucial that the content remains intact when decoding / encoding is used.
Checklist
I agree to follow the code of conduct.
I have read and understood the contribution guidelines.
I have read and understood Guava's philosophy, and I strongly believe that this proposal aligns with it.
The text was updated successfully, but these errors were encountered: