RFR: 8223553: Fix code constructs that do not compile with the Eclipse Java Compiler

Stuart Marks stuart.marks at oracle.com
Fri May 17 22:56:27 UTC 2019


Hi Christoph,

I'm still not entirely sure why this is so, but the introduction of a local 
variable in MethodHandles.java seems to make things work for Eclipse. Addition 
of a local variable seems to be minimally invasive, so it makes sense to see if 
this technique can be applied to other cases.

(In ConcurrentSkipListMap the issue seems to be solved by addition of wildcards, 
as I had suggested previously, and it cleans up the unchecked cast that was 
there in the first place. So I think that one is ok already.)

In ManagementFactory.java, an unchecked cast and warnings suppression is 
introduced, and in ExchangeImpl.java a helper method was introduced. I've found 
ways to introduce local variables that make Eclipse happy for these cases. 
(Well, on localized test cases; I haven't built the whole JDK with Eclipse.) See 
diffs below.

The type of the local variable in ExchangeImpl.java is a mouthful. Interestingly 
I had to change Function.identity() to the lambda x -> x. I think this is 
because Function.identity() returns a function that doesn't allow its return 
type to vary from its argument, whereas x -> x allows a widening conversion. 
(This might provide a clue as to the differences between javac and Eclipse here, 
but a full understanding eludes me.)

s'marks



diff -r 006dadb903ab 
src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java
--- 
a/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java 
Mon May 13 17:15:56 2019 -0700
+++ 
b/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java 
Fri May 17 15:46:14 2019 -0700
@@ -1712,9 +1712,7 @@
          Map<?,?> m = (Map<?,?>) o;
          try {
              Comparator<? super K> cmp = comparator;
-            @SuppressWarnings("unchecked")
-            Iterator<Map.Entry<?,?>> it =
-                (Iterator<Map.Entry<?,?>>)m.entrySet().iterator();
+            Iterator<? extends Map.Entry<?,?>> it = m.entrySet().iterator();
              if (m instanceof SortedMap &&
                  ((SortedMap<?,?>)m).comparator() == cmp) {
                  Node<K,V> b, n;
diff -r 006dadb903ab 
src/java.management/share/classes/java/lang/management/ManagementFactory.java
--- 
a/src/java.management/share/classes/java/lang/management/ManagementFactory.java 
Mon May 13 17:15:56 2019 -0700
+++ 
b/src/java.management/share/classes/java/lang/management/ManagementFactory.java 
Fri May 17 15:46:14 2019 -0700
@@ -872,12 +872,12 @@
      public static Set<Class<? extends PlatformManagedObject>>
             getPlatformManagementInterfaces()
      {
-        return platformComponents()
+        Stream<Class<? extends PlatformManagedObject>> pmos = platformComponents()
                  .stream()
                  .flatMap(pc -> pc.mbeanInterfaces().stream())
                  .filter(clazz -> 
PlatformManagedObject.class.isAssignableFrom(clazz))
-                .map(clazz -> clazz.asSubclass(PlatformManagedObject.class))
-                .collect(Collectors.toSet());
+                .map(clazz -> clazz.asSubclass(PlatformManagedObject.class));
+         return pmos.collect(Collectors.toSet());
      }

      private static final String NOTIF_EMITTER =
diff -r 006dadb903ab 
src/java.net.http/share/classes/jdk/internal/net/http/ExchangeImpl.java
--- a/src/java.net.http/share/classes/jdk/internal/net/http/ExchangeImpl.java 
Mon May 13 17:15:56 2019 -0700
+++ b/src/java.net.http/share/classes/jdk/internal/net/http/ExchangeImpl.java 
Fri May 17 15:46:14 2019 -0700
@@ -92,8 +92,9 @@
              CompletableFuture<Http2Connection> c2f = 
c2.getConnectionFor(request, exchange);
              if (debug.on())
                  debug.log("get: Trying to get HTTP/2 connection");
-            return c2f.handle((h2c, t) -> createExchangeImpl(h2c, t, exchange, 
connection))
-                    .thenCompose(Function.identity());
+            CompletableFuture<CompletableFuture<? extends ExchangeImpl<U>>> fxi =
+                c2f.handle((h2c, t) -> createExchangeImpl(h2c, t, exchange, 
connection));
+            return fxi.thenCompose(x -> x);
          }
      }




More information about the net-dev mailing list