Hi,

Over the weekend I tried to compile tapestry using OpenJDK and failed with
some problems with generics (mostly due the use of static methods in
CollectionsFactory). I diged a bit into this and here are my findings: some
errors are due the lack of the generic parameter when calling newList, ej
insted of writing CollectionsFactory.<String>newList() it was written
as CollectionsFactory.newList(). The rest of the problems is what I would
categorize as OpenJDK compiler bug, which is unable to figure out in some
contexts that a call to CollectionsFactory.newList(V... elements) will
return a list of V. Funny enough, while a construct like:

    String str = ...
    callMethodExpectingListOfStrings(CollectionsFactory.newList(str))

fail, the following construct does not:

    String str = ...
    List<String> lst = CollectionsFactory.newList(element);
    callMethodExpectingListOfStrings(lst)

I have attached a patch to solve those problems. With this patch tapestry
compiles just fine using OpenJDK. Should I open a Jira issue for this?

Regards,
Manuel.
From 460ca6615c5fe78521bfa64a3b8d14fccdf2d976 Mon Sep 17 00:00:00 2001
From: Manuel Sugawara <[email protected]>
Date: Mon, 5 Sep 2011 11:15:58 -0500
Subject: [PATCH] Modifications to generics code to allow tapestry to be
 compiled using openjdk. Some modifications are bugs in the
 code but some others are workarounds to what I think are
 bugs in the openjdk compiler.

---
 .../services/FieldValidatorSourceImpl.java         |    6 ++++--
 .../internal/transform/ComponentWorker.java        |    9 +++++++--
 .../services/ajax/JavaScriptSupportImplTest.java   |   12 ++++++++----
 .../internal/jpa/PersistenceUnitInfoImpl.java      |    6 ++++--
 4 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/FieldValidatorSourceImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/FieldValidatorSourceImpl.java
index df80222..f87c3fe 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/FieldValidatorSourceImpl.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/FieldValidatorSourceImpl.java
@@ -78,9 +78,11 @@ public class FieldValidatorSourceImpl implements FieldValidatorSource
 
         ValidatorSpecification originalSpec = new ValidatorSpecification(validatorType, constraintValue);
 
-        List<ValidatorSpecification> specs = expandMacros(newList(originalSpec));
+        List<ValidatorSpecification> org = CollectionFactory.newList(originalSpec);
 
-        List<FieldValidator> fieldValidators = CollectionFactory.newList();
+        List<ValidatorSpecification> specs = expandMacros(org);
+
+        List<FieldValidator> fieldValidators = CollectionFactory.<FieldValidator>newList();
 
         for (ValidatorSpecification spec : specs)
         {
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ComponentWorker.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ComponentWorker.java
index 6da6006..a18b8c6 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ComponentWorker.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ComponentWorker.java
@@ -14,6 +14,8 @@
 
 package org.apache.tapestry5.internal.transform;
 
+import java.util.List;
+
 import org.apache.tapestry5.ComponentResources;
 import org.apache.tapestry5.annotations.Component;
 import org.apache.tapestry5.annotations.MixinClasses;
@@ -120,8 +122,11 @@ public class ComponentWorker implements ComponentClassTransformWorker2
     {
         String names = annotation.publishParameters();
 
-        if (InternalUtils.isNonBlank(names))
-            embedded.setPublishedParameters(CollectionFactory.newList(TapestryInternalUtils.splitAtCommas(names)));
+        if (InternalUtils.isNonBlank(names)) {
+            List<String> published = CollectionFactory.newList(TapestryInternalUtils.splitAtCommas(names));
+            embedded.setPublishedParameters(published);
+        }
+
     }
 
     private void addMixinClasses(PlasticField field, MutableEmbeddedComponentModel model)
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImplTest.java b/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImplTest.java
index eb75a5c..71216ae 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImplTest.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImplTest.java
@@ -126,11 +126,13 @@ public class JavaScriptSupportImplTest extends InternalBaseTestCase
         JavaScriptStack stack = mockJavaScriptStack();
 
         StylesheetLink stylesheetLink = new StylesheetLink("style.css");
+        List<String> stackList = CollectionFactory.newList("stack1.js", "stack2.js");
 
         expect(stackSource.getStack(InternalConstants.CORE_STACK_NAME)).andReturn(stack);
         expect(pathConstructor.constructPathsForJavaScriptStack(InternalConstants.CORE_STACK_NAME)).andReturn(
-                CollectionFactory.newList("stack1.js", "stack2.js"));
-        expect(stack.getStylesheets()).andReturn(CollectionFactory.newList(stylesheetLink));
+                stackList);
+        List<StylesheetLink> stylesheetLst = CollectionFactory.newList(stylesheetLink);
+        expect(stack.getStylesheets()).andReturn(stylesheetLst);
 
         expect(stack.getInitialization()).andReturn("stackInit();");
 
@@ -257,11 +259,13 @@ public class JavaScriptSupportImplTest extends InternalBaseTestCase
         JavaScriptStack stack = mockJavaScriptStack();
 
         StylesheetLink stylesheetLink = new StylesheetLink("stack.css");
+        List<String> stackLst = CollectionFactory.newList("stack.js");
 
         expect(stackSource.getStack("custom")).andReturn(stack);
         expect(pathConstructor.constructPathsForJavaScriptStack("custom")).andReturn(
-                CollectionFactory.newList("stack.js"));
-        expect(stack.getStylesheets()).andReturn(CollectionFactory.newList(stylesheetLink));
+                stackLst);
+        List<StylesheetLink> stylesheetLst = CollectionFactory.newList(stylesheetLink);
+        expect(stack.getStylesheets()).andReturn(stylesheetLst);
 
         expect(stack.getInitialization()).andReturn("customInit();");
 
diff --git a/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/PersistenceUnitInfoImpl.java b/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/PersistenceUnitInfoImpl.java
index 290b839..36dd84d 100644
--- a/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/PersistenceUnitInfoImpl.java
+++ b/tapestry-jpa/src/main/java/org/apache/tapestry5/internal/jpa/PersistenceUnitInfoImpl.java
@@ -152,7 +152,8 @@ public class PersistenceUnitInfoImpl implements TapestryPersistenceUnitInfo
      */
     public List<String> getMappingFileNames()
     {
-        return Collections.unmodifiableList(CollectionFactory.newList(mappingFilesNames));
+        List<String> tmp = CollectionFactory.newList(mappingFilesNames);
+        return Collections.unmodifiableList(tmp);
     }
 
     /**
@@ -233,7 +234,8 @@ public class PersistenceUnitInfoImpl implements TapestryPersistenceUnitInfo
      */
     public List<String> getManagedClassNames()
     {
-        return Collections.unmodifiableList(CollectionFactory.newList(managedClassNames));
+        List<String> tmp = CollectionFactory.newList(managedClassNames);
+        return Collections.<String>unmodifiableList(tmp);
     }
 
     /**
-- 
1.7.4.4

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to