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

Javac demands that initializer must complete normally

XMLWordPrintable

    • kestrel
    • generic
    • generic



      Name: dkC59003 Date: 07/12/99



      Javac releases shipped with JDK 1.2, 1.2.1, and 1.2.2 demand
      that "Initializer must be able to complete normally.", and
      reject the following classes:

          class UncheckedExceptionInInitializer {
              boolean stopIt = true;
              { // passed
                  if (stopIt)
                      throw new RuntimeException();
              };

              { // failed
                  throw new RuntimeException();
              };
          }

          class UncheckedExceptionInStaticInitializer {
              static boolean stopIt = true;
              static { // passed
                  if (stopIt)
                      throw new RuntimeException();
              };

              static { // failed
                  throw new RuntimeException();
              };
          }

          class ErrorThrownInInitializer {
              { // passed
                  boolean truth=true;
                  if (truth)
                      throw new Error();
              };

              { // failed
                  throw new Error();
              };
          }

          class ErrorThrownInStaticInitializer {
              static { // passed
                  boolean truth=true;
                  if (truth)
                      throw new Error();
              };

              static { // failed
                  throw new Error();
              };
          }

          class InfiniteCycleInInitializer {
              { // passed
                  boolean truth=true;
                  while (truth);
              };
              { // failed
      while (true);
              };

              void pass () {
                  while (true);
              };
          }

          class InfiniteCycleInStaticInitializer {
              static { // failed
                  while (true);
              };
              static void pass () {
                  while (true);
              };
          }

      Compiler prints the same diagnistics for these classes:

          >>>> $JAVAC *.java
          ErrorThrownInInitializer.java:8: Initializer must be able to complete normally.
              { // failed
              ^
          ErrorThrownInStaticInitializer.java:8: Initializer must be able to complete normally.
              static { // failed
              ^
          InfiniteCycleInInitializer.java:6: Initializer must be able to complete normally.
              { // failed
              ^
          InfiniteCycleInStaticInitializer.java:2: Initializer must be able to complete normally.
              static { // failed
              ^
          UncheckedExceptionInInitializer.java:8: Initializer must be able to complete normally.
              { // failed
              ^
          UncheckedExceptionInStaticInitializer.java:8: Initializer must be able to complete normally.
              static { // failed
              ^
          6 errors

      However, I could not find if JSL demands that:
          "Initializer must be able to complete normally."
      nor even that:
          "Initializer must be able to complete."
          (i.e.: if initializer should not hang up.)

      Note, that the JLS section 11.2 states, that variable initializers for fields
      and static initializers must not result in a checked exception. However, there
      is no limitation, that they must not result in unchecked exception. (See the bug
      #4102541, which concerns incorrect processing of unchecked exception in instance
      field initializer.)

      Also note, that there is no unreachable statements after "while(true)" cycle in
      InfiniteCycleInInitializer nor in InfiniteCycleInStaticInitializer classes.
      (See the bugreport #4063938 for discussion on unreachable statements in static
      initializers.)

      ======================================================================

            wmaddoxsunw William Maddox (Inactive)
            dkhukhrosunw Dmitry Khukhro (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: