sklaha commented on code in PR #249: URL: https://github.com/apache/cassandra-sidecar/pull/249#discussion_r2291586222
########## adapters/adapters-base/src/main/java/org/apache/cassandra/sidecar/adapters/base/data/CompositeDataUtil.java: ########## @@ -50,4 +50,55 @@ public static <T> T extractValue(CompositeData data, String key) throw new RuntimeException("Value type mismatched of key: " + key, cce); } } + + /** + * Safely casts an object to the specified type with descriptive error handling. + * This method performs a runtime type check before casting to prevent ClassCastException + * and provides meaningful error messages when the cast fails. + * + * @param value the object to be cast + * @param expectedType the expected type to cast to + * @param contextDescription descriptive context for error messages (e.g., "keyspace name", "table data") + * @param <T> the target type + * @return the cast object of type T + * @throws IllegalStateException if the value is not an instance of the expected type, + * with a descriptive message indicating what was expected vs what was received + */ + public static <T> T safeCast(Object value, Class<T> expectedType, String contextDescription) Review Comment: Added unit tests. -- 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. To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For additional commands, e-mail: pr-h...@cassandra.apache.org