8024609: sjavac assertion fails during call to BuildState.collectArtifacts
authorohrstrom
Thu, 19 Sep 2013 08:26:26 -0700
changeset 20241 1e178dbe29c1
parent 20240 1818352eef49
child 20242 11fa75a0b9fb
8024609: sjavac assertion fails during call to BuildState.collectArtifacts Reviewed-by: jjg
langtools/src/share/classes/com/sun/tools/sjavac/BuildState.java
langtools/src/share/classes/com/sun/tools/sjavac/Main.java
langtools/src/share/classes/com/sun/tools/sjavac/server/JavacServer.java
--- a/langtools/src/share/classes/com/sun/tools/sjavac/BuildState.java	Thu Sep 19 17:05:08 2013 +0200
+++ b/langtools/src/share/classes/com/sun/tools/sjavac/BuildState.java	Thu Sep 19 08:26:26 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -81,12 +81,13 @@
     }
 
     /**
-     * Collect all packages, sources and artifacts for all modules
-     * into the build state.
+     * Store references to all packages, sources and artifacts for all modules
+     * into the build state. I.e. flatten the module tree structure
+     * into global maps stored in the BuildState for easy access.
      *
      * @param m The set of modules.
      */
-    public void collectPackagesSourcesAndArtifacts(Map<String,Module> m) {
+    public void flattenPackagesSourcesAndArtifacts(Map<String,Module> m) {
         modules = m;
         // Extract all the found packages.
         for (Module i : modules.values()) {
@@ -121,11 +122,12 @@
     }
 
     /**
-     * Collect all the artifacts of all modules and packages.
+     * Store references to all artifacts found in the module tree into the maps
+     * stored in the build state.
      *
      * @param m The set of modules.
      */
-    public void collectArtifacts(Map<String,Module> m) {
+    public void flattenArtifacts(Map<String,Module> m) {
         modules = m;
         // Extract all the found packages.
         for (Module i : modules.values()) {
@@ -270,6 +272,8 @@
             Module mnew = findModuleFromPackageName(pkg);
             Package pprev = prev.packages().get(pkg);
             mnew.addPackage(pprev);
+            // Do not forget to update the flattened data.
+            packages.put(pkg, pprev);
         }
     }
 }
--- a/langtools/src/share/classes/com/sun/tools/sjavac/Main.java	Thu Sep 19 17:05:08 2013 +0200
+++ b/langtools/src/share/classes/com/sun/tools/sjavac/Main.java	Thu Sep 19 08:26:26 2013 -0700
@@ -274,7 +274,7 @@
 //          findFiles(args, "-modulepath", Util.set(".class"), modules_to_link_to, modules, current_module, true);
 
             // Add the set of sources to the build database.
-            javac_state.now().collectPackagesSourcesAndArtifacts(modules);
+            javac_state.now().flattenPackagesSourcesAndArtifacts(modules);
             javac_state.now().checkInternalState("checking sources", false, sources);
             javac_state.now().checkInternalState("checking linked sources", true, sources_to_link_to);
             javac_state.setVisibleSources(sources_to_link_to);
@@ -311,7 +311,7 @@
             Map<String,Source> generated_sources = new HashMap<String,Source>();
             Source.scanRoot(gensrc_dir, Util.set(".java"), null, null, null, null,
                    generated_sources, modules, current_module, false, true, false);
-            javac_state.now().collectPackagesSourcesAndArtifacts(modules);
+            javac_state.now().flattenPackagesSourcesAndArtifacts(modules);
             // Recheck the the source files and their timestamps again.
             javac_state.checkSourceStatus(true);
 
@@ -336,8 +336,8 @@
             // Only update the state if the compile went well.
             if (rc[0]) {
                 javac_state.save();
-                // Collect all the artifacts.
-                javac_state.now().collectArtifacts(modules);
+                // Reflatten only the artifacts.
+                javac_state.now().flattenArtifacts(modules);
                 // Remove artifacts that were generated during the last compile, but not this one.
                 javac_state.removeSuperfluousArtifacts(recently_compiled);
             }
--- a/langtools/src/share/classes/com/sun/tools/sjavac/server/JavacServer.java	Thu Sep 19 17:05:08 2013 +0200
+++ b/langtools/src/share/classes/com/sun/tools/sjavac/server/JavacServer.java	Thu Sep 19 08:26:26 2013 -0700
@@ -464,7 +464,7 @@
             PrintStream err) {
         int rc = -3;
         try {
-            int port = portFile.getPort();
+            int port = portFile.containsPortInfo() ? portFile.getPort() : 0;
             if (port == 0) {
                 return ERROR_BUT_TRY_AGAIN;
             }