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

Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • 5.0, 6, 7, 8, 9
    • core-libs
    • b34
    • generic
    • generic
    • Verified

        FileHandler constructor NullPointerException - if pattern property is an empty String, but if count > 1
        exception won't be thrown.

        Example Main.java:

        import java.util.logging.FileHandler;

        public class Main {

            public static void main(String[] args) {
                FileHandler fh = null;
                try {
                    fh = new FileHandler();
                    System.out.println("fail");
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    if (fh != null) {
                        fh.close();
                    }
                }
            }
        }

        property file: pr.properties:
        java.util.logging.FileHandler.count = 2
        java.util.logging.FileHandler.pattern=

        Run:
        jdk1.7.0_45b09\bin\java.exe -Djava.util.logging.config.file=pr.properties Main
        fail

        file with name .0 will be created in the current folder

        If we change pr.properties:
        java.util.logging.FileHandler.count = 1
        java.util.logging.FileHandler.pattern=

        and run again:
        jdk1.7.0_45b09\bin\java.exe -Djava.util.logging.config.file=pr.properties Main
        java.lang.NullPointerException
                at java.util.logging.FileHandler.openFiles(FileHandler.java:392)
                at java.util.logging.FileHandler.<init>(FileHandler.java:225)
                at Main.main(Main.java:8)

        NPE was thrown as expected.

              dfuchs Daniel Fuchs
              psemenov Pavel Semenov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: