Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8152926

PropertyResourceBundle constructor don't understand the System.setProperty change

XMLWordPrintable

    • 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.

            okutsu Masayoshi Okutsu
            vaibhav Vaibhav Choudhary (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: