-
Bug
-
Resolution: Fixed
-
P2
-
9
-
b142
-
Not verified
Here is a small snippet to understand the issue :-
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.MalformedInputException;
import java.nio.charset.UnmappableCharacterException;
import java.util.PropertyResourceBundle;
public class StrictUTF8SequencesTest {
static byte[] illegal_sequences =
new byte[]{(byte) 0xc0, (byte) 0x80}; // invalid UTF-8 Sequence - non-shortest form
public static void main(String[] args) throws Exception {
System.setProperty("java.util.PropertyResourceBundle.encoding", "UTF-8");
try (InputStream input = new ByteArrayInputStream(illegal_sequences)) {
new PropertyResourceBundle(input);
} catch (UnmappableCharacterException | MalformedInputException e) {
System.out.println("Should reach here");
}
System.clearProperty("java.util.PropertyResourceBundle.encoding");
// this code should not throw exception.
try (InputStream input = new ByteArrayInputStream(illegal_sequences)) {
new PropertyResourceBundle(input);
}
}
}
- In this code, after clearing "java.util.PropertyResourceBundle.encoding", it should not throw exception. In stead of that, it should execute the code successfully with INFO message "INFO: Invalid or unmappable UTF-8 sequence detected. Switching encoding from UTF-8 to ISO-8859-1"
- The later part of the code, should behave consistently with or without the upper part of the code, as we are clearing the system property and it is now not strict UTF-8.
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.MalformedInputException;
import java.nio.charset.UnmappableCharacterException;
import java.util.PropertyResourceBundle;
public class StrictUTF8SequencesTest {
static byte[] illegal_sequences =
new byte[]{(byte) 0xc0, (byte) 0x80}; // invalid UTF-8 Sequence - non-shortest form
public static void main(String[] args) throws Exception {
System.setProperty("java.util.PropertyResourceBundle.encoding", "UTF-8");
try (InputStream input = new ByteArrayInputStream(illegal_sequences)) {
new PropertyResourceBundle(input);
} catch (UnmappableCharacterException | MalformedInputException e) {
System.out.println("Should reach here");
}
System.clearProperty("java.util.PropertyResourceBundle.encoding");
// this code should not throw exception.
try (InputStream input = new ByteArrayInputStream(illegal_sequences)) {
new PropertyResourceBundle(input);
}
}
}
- In this code, after clearing "java.util.PropertyResourceBundle.encoding", it should not throw exception. In stead of that, it should execute the code successfully with INFO message "INFO: Invalid or unmappable UTF-8 sequence detected. Switching encoding from UTF-8 to ISO-8859-1"
- The later part of the code, should behave consistently with or without the upper part of the code, as we are clearing the system property and it is now not strict UTF-8.