sruehl commented on a change in pull request #8: cleanup warnings in plc4j-api, 
plc4j-core, dummy-driver
URL: https://github.com/apache/incubator-plc4x/pull/8#discussion_r170832548
 
 

 ##########
 File path: 
plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/specific/TypeSafePlcReadResponse.java
 ##########
 @@ -59,17 +59,49 @@ public TypeSafePlcReadResponse(TypeSafePlcReadRequest<T> 
request, List<ReadRespo
         return (Optional<ReadResponseItem<T>>) super.getResponseItem();
     }
 
+    /**
+     * Cast or convert a PlcReadResponse to a TypeSafePlcReadReadResponse<T>.
+     * 
+     * WARNING: this is inherently a non-type-safe operation.  It was 
introduced
+     * to serve the implementation of 
PlcReader.read(TypeSafePlcReadRequest<T>).
+     * Additional use of it is not recommended.  This interface is subject to 
change.
+     * 
+     * @param plcReadResponse the response implicitly with items of type T
+     * @return TypeSafePlcReadReadResponse<T>
+     */
     @SuppressWarnings("unchecked")
     public static <T> TypeSafePlcReadResponse<T> of(PlcReadResponse 
plcReadResponse) {
+        // BUG: there seems to be no checking that the readResponse/items
+        // in fact are for type T.
+        // I don't even think it's possible to do that with the current 'of()' 
signature
+        // and plcReadResponse content.
+        //
+        // The only consolation is that currently, 'of()' is only really used 
in the
+        // impl of PlcReader.read(TypeSafePlcReadRequest<T>) and that case 
guarantees
+        // that all items are a T.  plcReadResponse isa 
TypeSafePlcReadResponse in
+        // this case.
+        //
+        // Maybe we just need to doc that this conversion is unsafe and/or 
rename
+        // the method to "unsafeOf()"? 
+        // Or, if there were an AbstractPlcReader<T>, that could internally 
implement
+        // this method without exposing this generally it, the PlcReader 
interface
+        // could remove the default implementation of 
read(TypeSafePlcReadRequest<T>),
+        // and protocol implementations could extend AbstractPlcReader.
+        //
+        // FWIW, in one case there is some checking that all of the items in a 
response
+        // are at least of the same type.
+      
         if (plcReadResponse instanceof TypeSafePlcReadResponse) {
-            return (TypeSafePlcReadResponse) plcReadResponse;
+            // Warning: no validation that everything in the response is a T.
 
 Review comment:
   then we would need to check here if the requested `Class class` is equals to 
the supplied type

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to