mike-jumper commented on a change in pull request #546:
URL: https://github.com/apache/guacamole-client/pull/546#discussion_r513946820



##########
File path: 
guacamole/src/main/java/org/apache/guacamole/rest/connection/ConnectionResource.java
##########
@@ -150,18 +153,26 @@ public ConnectionResource(@Assisted UserContext 
userContext,
      * @throws GuacamoleException
      *     If an error occurs while retrieving the connection history.
      */
-    @GET
+    @SuppressWarnings("deprecation")
     @Path("history")
-    public List<APIConnectionRecord> getConnectionHistory()
+    public ConnectionHistoryResource getConnectionHistory()
             throws GuacamoleException {
 
-        // Retrieve the requested connection's history
-        List<APIConnectionRecord> apiRecords = new 
ArrayList<APIConnectionRecord>();
-        for (ConnectionRecord record : connection.getHistory())
-            apiRecords.add(new APIConnectionRecord(record));
-
-        // Return the converted history
-        return apiRecords;
+        try {
+            return new 
ConnectionHistoryResource(connection.getConnectionHistory());
+        }
+        catch (GuacamoleUnsupportedException e) {
+            try {
+                List<ConnectionRecord> history = Collections.emptyList();
+                for (ConnectionRecord record : connection.getHistory()) {
+                    history.add(record);
+                }
+                return new ConnectionHistoryResource(new 
SimpleActivityRecordSet<>(history));
+            }
+            catch (GuacamoleUnsupportedException ex) {
+                return new ConnectionHistoryResource(new 
SimpleActivityRecordSet<>());
+            }
+        }

Review comment:
       Ah, I see what you're saying. It's a rather confusing aspect of Java 
generics. Consider if this was possible:
   
   ```java
   List<FancyThing> a = new ArrayList<>();
   List<? extends Thing> b = a; // This is completely OK
   List<Thing> c = b; // This shouldn't be allowed because ...
   c.add(new Thing()); // ... this breaks the contract of List<FancyThing>
   ```
   
   Suddenly, that `List` that's expected to contain only fancy things contains 
a non-fancy thing, breaking the contract of the type. Declaring something as 
`List<Thing>` is saying "a list of `Thing` or any subclass of `Thing`". 
Declaring something as `List<? extends Thing>` is saying "a list of **an 
unspecified subclass of `Thing`**".
   
   For the approach here with `SimpleActivityRecordSet`:
   
   * There is a convenient way to turn `List<? extends T>` into `List<T>`, 
[`Collections.unmodifiableList()`](https://docs.oracle.com/javase/8/docs/api/java/util/Collections.html#unmodifiableList-java.util.List-).
   * If you're adding a convenience constructor to `SimpleActivityRecordSet()` 
that accepts a list of records, you should probably use `List<? extends 
RecordType>` for the parameter so that it can accept any `List` having usable 
elements. This is what `ArrayList` does, presumably for the same reason: 
https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html#ArrayList-java.util.Collection-




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to