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

compilation fail in first run after clearing output folder but not in second run

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Confirmed with javac 1.7.0_80, javac 1.8.0_131,javac 17.0.1

      A DESCRIPTION OF THE PROBLEM :
      Under certain conditions due to double-indirect compile time dependencies compilation correctly reports errors in first run after clearing output folder (deleting class files) but does NOT report an error (incorrect behavior) on second run (without clearing class files) if an error happens in file compiled due to at least double indirect dependency.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Take files as shown in source code test case.

      Those files are such as following compile-time dependencies are present:

      Class bugreport.S directly requires class bugreport.sub.A
      Class bugreport.sub.A directly requires class bugreport.sub.C and bugreport.sub.D
      Class bugreport.sub.D directly requires class bugreport.sub.C
      Class bugreport.sub.C directly requires class bugreport.sub2.Z
      Class bugreport.sub2.Z directly requires some non-existing class and fails to compile.

      The:

      javac -cp .\out -sourcepath ..\ -d .\out S.java

      is used to compile S class.

      Clear "out" folder.

      Issue this command TWICE without clearing "out" folder in between calls.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Expected result:
      1.Compilation always fails, regardless how many times command is issued and result is independent of if "out" was cleared or not.
      2.If compilation of class X fails then no class file is produced for it AND
      all class files which during this compilation depended on class X are not produced too.
      ACTUAL -
      First compilation fails as expected with:

      ..\bugreport\sub2\Z.java:6: error: package bugreport.sub3 does not exist
                      return new bugreport.sub3.X(); //fail

      however following class files ARE produced:

      └───bugreport
          │ S.class
          │
          └───sub
                  A.class
                  C.class *** NOTICE THIS CLASS ***
                  D.class

      Notice, C class WAS PRODUCED even tough a direct attempt to compile it FAILS
      because of direct dependency on Z which can't be compiled at all.

      Due to that file structure second attempt to compile S.class finishes without
      any error, however the compiled set of classes is incomplete and will:
      1. Fail to link at runtime.
      2. Fail to compile from scratch on an another workstation.

      ---------- BEGIN SOURCE ----------
      package bugreport;
      import bugreport.sub.*;
      public class S
      {
      public Object m()
      {
      return new A();
      };
      };
      package bugreport.sub;
      public class A
      {
      public Object b()
      {
      return new C();
      };
      public Object c()
      {
      return new D();
      };
      };
      package bugreport.sub;
      import bugreport.sub2.*;
      public class C
      {
      public void b()
      {
      //depend on failing class from another package
      new Z();
      };
      };
      package bugreport.sub;
      public class D
      {
      public Object b()
      {
      //mimmic direct dependendy on CImageExportAction
      return new C();
      };
      };
      package bugreport.sub2;
      public class Z
      {
      public Object b()
      {
      //return null;
      return new bugreport.sub3.X(); //fail
      };
      };

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Investigation

      This problem appears as long as long as there is at least a double-indirect dependency.

      This is related to -implicit:class option and -Xprefer:source option

      If -implicit:none is specified this compile time error is present regardless of how many times compilation is run at the cost of not producing files needed to
      fulfill link-time dependencies. So this is not a work around, as I would expect that compilation of S will produce all classes necessary if there is no compilation error.

      If -Xprefer:source is specified it behaves as expected at the cost of some performance issues, so I may say, that using -Xprefer:source is a good work-around but not a true solution.

      And by the way, good work with JAVA. I like what You do and how well it works.


      FREQUENCY : always


        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated: