[
https://issues.apache.org/jira/browse/CASSJAVA-16?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Bret McGuire updated CASSJAVA-16:
---------------------------------
Fix Version/s: 4.18.1
(was: 4.18.0)
> Replace uses of AttributeKey.newInstance with AttributeKey.valueOf in
> cassandra-java-driver
> -------------------------------------------------------------------------------------------
>
> Key: CASSJAVA-16
> URL: https://issues.apache.org/jira/browse/CASSJAVA-16
> Project: Apache Cassandra Java driver
> Issue Type: Bug
> Reporter: Andy Tolbert
> Assignee: Andy Tolbert
> Priority: Normal
> Fix For: 4.18.1
>
> Time Spent: 1h 10m
> Remaining Estimate: 0h
>
> The java driver uses netty channel attributes to decorate a connection's
> channel with the cluster name (returned from the system.local table) and the
> map from the {{OPTIONS}} response, both of which are obtained on connection
> initialization.
> There's an issue here that I wouldn't expect to see in practice in that the
> {{AttributeKey}}'s used are created using {{AttributeKey.newInstance}}, which
> throws an exception if an {{AttributeKey}} of that name is defined anywhere
> else in evaluated code.
> https://github.com/apache/cassandra-java-driver/blob/8d5849cb38995b312f29314d18256c0c3e94cf07/core/src/main/java/com/datastax/oss/driver/internal/core/channel/DriverChannel.java#L52-L54
> {code:java}
> static final AttributeKey<String> CLUSTER_NAME_KEY =
> AttributeKey.newInstance("cluster_name");
> static final AttributeKey<Map<String, List<String>>> OPTIONS_KEY =
> AttributeKey.newInstance("options");
> {code}
> This was encountered by a user that was creating driver connections within a
> trigger: https://the-asf.slack.com/archives/CJZLTM05A/p1705537114305579
> {noformat}
> Caused by: java.lang.IllegalArgumentException: 'cluster_name' is
> already in use
> at
> io.netty.util.ConstantPool.createOrThrow(ConstantPool.java:109)
> at io.netty.util.ConstantPool.newInstance(ConstantPool.java:91)
> at io.netty.util.AttributeKey.newInstance(AttributeKey.java:55)
> at
> com.datastax.oss.driver.internal.core.channel.DriverChannel.<clinit>(DriverChannel.java:50)
> ... 30 common frames omitted
> {noformat}
> There is likely some class loading oddness in the Trigger implementation that
> exacerbates the problem. But at the least, if the driver were to use
> AttributeKey.valueOf instead (like Cassandra does where it uses them:
> https://github.com/search?q=repo%3Aapache%2Fcassandra+AttributeKey.valueOf&type=code),
> this particular issue could be avoided.
> Debatably we could use {{valueOf(firstNameComponent,secondNameComponent)}} as
> a way of namespacing the attribute (e.g.
> {{AttributeKey.newInstance("com.datastax.oss.driver.internal.core.channel",
> "cluster_name");}}, this does not seem necessary though.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]