OpenJDK has some issues inferring generic types in some cases.  There was
some attempt to address it <http://markmail.org/message/cen3lghawfnnxxgp>,
but it turned out to be a partial fix and there was some concern that the
older javac was improperly allowing some of these constructs.

External users are starting to run into this as newer Linux distros are
moving to OpenJDK for the default Java install, so I think we should go
ahead and fix it in our code base.  The attached patch, relative to trunk
r5098, fixes this by adding temporary variables to avoid the bug.

-- 
John A. Tamplin
Software Engineer (GWT), Google

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Index: dev/oophm/overlay/com/google/gwt/dev/GWTShell.java
===================================================================
--- dev/oophm/overlay/com/google/gwt/dev/GWTShell.java	(revision 5098)
+++ dev/oophm/overlay/com/google/gwt/dev/GWTShell.java	(working copy)
@@ -32,6 +32,7 @@
 import java.io.File;
 import java.net.URL;
 import java.util.Set;
+import java.util.SortedSet;
 
 import javax.swing.ImageIcon;
 
@@ -249,7 +250,9 @@
          * Copied from StandardLinkerContext.produceOutputDirectory() for legacy
          * GWTShellServlet support.
          */
-        for (EmittedArtifact artifact : artifacts.find(EmittedArtifact.class)) {
+        // Use a temporary variable to avoid an OpenJDK generic inference bug.
+        SortedSet<EmittedArtifact> emittedArtifacts = artifacts.find(EmittedArtifact.class);
+        for (EmittedArtifact artifact : emittedArtifacts) {
           if (!artifact.isPrivate()) {
             File outFile = new File(options.getShellPublicGenDir(module),
                 artifact.getPartialPath());
@@ -260,6 +263,7 @@
     };
   }
 
+  
   @Override
   protected void doShutDownServer() {
     // Stop the HTTP server.
Index: dev/core/src/com/google/gwt/core/ext/linker/impl/SelectionScriptLinker.java
===================================================================
--- dev/core/src/com/google/gwt/core/ext/linker/impl/SelectionScriptLinker.java	(revision 5098)
+++ dev/core/src/com/google/gwt/core/ext/linker/impl/SelectionScriptLinker.java	(working copy)
@@ -103,7 +103,9 @@
       ArtifactSet artifacts) throws UnableToCompleteException {
     ArtifactSet toReturn = new ArtifactSet(artifacts);
 
-    for (CompilationResult compilation : toReturn.find(CompilationResult.class)) {
+    // Use a temporary variable to avoid an OpenJDK generic inference bug.
+    SortedSet<CompilationResult> compilationResults = toReturn.find(CompilationResult.class);
+    for (CompilationResult compilation : compilationResults) {
       toReturn.addAll(doEmitCompilation(logger, context, compilation));
     }
 
@@ -226,7 +228,9 @@
     // Add external dependencies
     startPos = selectionScript.indexOf("// __MODULE_STYLES_END__");
     if (startPos != -1) {
-      for (StylesheetReference resource : artifacts.find(StylesheetReference.class)) {
+      // Use a temporary variable to avoid an OpenJDK generic inference bug.
+      SortedSet<StylesheetReference> stylesheetReferences = artifacts.find(StylesheetReference.class);
+      for (StylesheetReference resource : stylesheetReferences) {
         String text = generateStylesheetInjector(resource.getSrc());
         selectionScript.insert(startPos, text);
         startPos += text.length();
@@ -235,7 +239,9 @@
 
     startPos = selectionScript.indexOf("// __MODULE_SCRIPTS_END__");
     if (startPos != -1) {
-      for (ScriptReference resource : artifacts.find(ScriptReference.class)) {
+      // Use a temporary variable to avoid an OpenJDK generic inference bug.
+      SortedSet<ScriptReference> scriptReferences = artifacts.find(ScriptReference.class);
+      for (ScriptReference resource : scriptReferences) {
         String text = generateScriptInjector(resource.getSrc());
         selectionScript.insert(startPos, text);
         startPos += text.length();
@@ -253,6 +259,7 @@
     }
 
     // Possibly add permutations
+    // Use a temporary variable to avoid an OpenJDK generic inference bug.
     SortedSet<CompilationResult> compilations = artifacts.find(CompilationResult.class);
     startPos = selectionScript.indexOf("// __PERMUTATIONS_END__");
     if (startPos != -1) {
Index: dev/core/src/com/google/gwt/core/ext/linker/impl/StandardLinkerContext.java
===================================================================
--- dev/core/src/com/google/gwt/core/ext/linker/impl/StandardLinkerContext.java	(revision 5098)
+++ dev/core/src/com/google/gwt/core/ext/linker/impl/StandardLinkerContext.java	(working copy)
@@ -435,7 +435,9 @@
     logger = logger.branch(TreeLogger.TRACE, "Linking compilation into "
         + outputPath.getPath(), null);
 
-    for (EmittedArtifact artifact : artifacts.find(EmittedArtifact.class)) {
+    // Use a temporary variable to avoid an OpenJDK generic inference bug.
+    SortedSet<EmittedArtifact> emittedArtifacts = artifacts.find(EmittedArtifact.class);
+    for (EmittedArtifact artifact : emittedArtifacts) {
       TreeLogger artifactLogger = logger.branch(TreeLogger.DEBUG,
           "Emitting resource " + artifact.getPartialPath(), null);
 
@@ -456,7 +458,9 @@
         outFile.setLastModified(artifact.getLastModified());
       }
     }
-    for (StandardCompilationAnalysis soycFiles : artifacts.find(StandardCompilationAnalysis.class)) {
+    // Use a temporary variable to avoid an OpenJDK generic inference bug.
+    SortedSet<StandardCompilationAnalysis> analyses = artifacts.find(StandardCompilationAnalysis.class);
+    for (StandardCompilationAnalysis soycFiles : analyses) {
       TreeLogger artifactLogger = logger.branch(TreeLogger.DEBUG,
           "Emitting soyc resources.", null);
       File depFile = new File(extraPath + "/soycReport",
Index: dev/core/src/com/google/gwt/core/linker/SymbolMapsLinker.java
===================================================================
--- dev/core/src/com/google/gwt/core/linker/SymbolMapsLinker.java	(revision 5098)
+++ dev/core/src/com/google/gwt/core/linker/SymbolMapsLinker.java	(working copy)
@@ -32,6 +32,7 @@
 import java.net.URI;
 import java.util.Map;
 import java.util.SortedMap;
+import java.util.SortedSet;
 
 /**
  * This Linker exports the symbol maps associated with each compilation result
@@ -59,7 +60,9 @@
 
     artifacts = new ArtifactSet(artifacts);
 
-    for (CompilationResult result : artifacts.find(CompilationResult.class)) {
+    // Use a temporary variable to avoid an OpenJDK generic inference bug.
+    SortedSet<CompilationResult> compilationResults = artifacts.find(CompilationResult.class);
+    for (CompilationResult result : compilationResults) {
       ByteArrayOutputStream out = new ByteArrayOutputStream();
       PrintWriter pw = new PrintWriter(out);
 
Index: dev/core/src/com/google/gwt/dev/GWTShell.java
===================================================================
--- dev/core/src/com/google/gwt/dev/GWTShell.java	(revision 5098)
+++ dev/core/src/com/google/gwt/dev/GWTShell.java	(working copy)
@@ -30,6 +30,7 @@
 import com.google.gwt.util.tools.ToolBase;
 
 import java.io.File;
+import java.util.SortedSet;
 
 /**
  * The main executable class for the hosted mode shell.
@@ -212,7 +213,9 @@
          * Copied from StandardLinkerContext.produceOutputDirectory() for legacy
          * GWTShellServlet support.
          */
-        for (EmittedArtifact artifact : artifacts.find(EmittedArtifact.class)) {
+        // Use a temporary variable to avoid an OpenJDK generic inference bug.
+        SortedSet<EmittedArtifact> emittedArtifacts = artifacts.find(EmittedArtifact.class);
+        for (EmittedArtifact artifact : emittedArtifacts) {
           if (!artifact.isPrivate()) {
             File outFile = new File(options.getShellPublicGenDir(module),
                 artifact.getPartialPath());

Reply via email to