Skip to content

com.google.cloud.datastore.BaseKey.Builder is defined in a way that doesn't allow reflection. #2226

@jrdoane

Description

@jrdoane

The com.google.cloud.datastore.BaseKey.Builder subclass has the protected accessor applied to the sub-class itself. While this normally wouldn't cause a problem with regular use in Java, it does cause an IllegalArgumentException when reflection is done to dynamically call a method on the protected sub-class. This is particularly problematic when Clojure is used because most inter-op with Java involves reflection.

So, if a builder has already been created and the setKind method is dynamically called, this occurs:

IllegalArgumentException Can't call public method of non-public class: public com.google.cloud.datastore.BaseKey$Builder com.google.cloud.datastore.BaseKey$Builder.setKind(java.lang.String) clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:88)

This happens when attempting to use Clojure to call .setKind on an instance of com.google.cloud.datastore.KeyFactory produced by calling newKeyFactory on an instance of com.google.cloud.datastore.Datastore.

This can be solved by changing the sub-class accessor to public instead of being set to protected.

Metadata

Metadata

Assignees

Labels

api: datastoreIssues related to the Datastore API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions