Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ggj] Generated classes which implement ResourceName do not use fully qualified names for java.lang classes #798

Closed
BenWhitehead opened this issue Jul 26, 2021 · 2 comments · Fixed by #803
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@BenWhitehead
Copy link
Contributor

Steps to reproduce

  1. Attempt to generate gapic client for storage/v2
  2. Receive compile error
    [ERROR] .../src/github.com/googleapis/java-storage/proto-google-cloud-storage-v2/src/main/java/com/google/storage/v2/CryptoKeyName.java:[173,3] method does not override or implement a method from a supertype
    [ERROR] .../src/github.com/googleapis/java-storage/proto-google-cloud-storage-v2/src/main/java/com/google/storage/v2/CryptoKeyName.java:[175,11] incomparable types: com.google.storage.v2.Object and com.google.storage.v2.CryptoKeyName
    [ERROR] .../src/github.com/googleapis/java-storage/proto-google-cloud-storage-v2/src/main/java/com/google/storage/v2/CryptoKeyName.java:[178,33] incomparable types: java.lang.Class<capture#1 of ? extends com.google.storage.v2.CryptoKeyName> and java.lang.Class<capture#2 of ? extends com.google.storage.v2.Object>
    [ERROR] .../src/github.com/googleapis/java-storage/proto-google-cloud-storage-v2/src/main/java/com/google/storage/v2/CryptoKeyName.java:[179,45] incompatible types: com.google.storage.v2.Object cannot be converted to com.google.storage.v2.CryptoKeyName
    [ERROR] .../src/github.com/googleapis/java-storage/proto-google-cloud-storage-v2/src/main/java/com/google/storage/v2/BucketName.java:[135,3] method does not override or implement a method from a supertype
    [ERROR] .../src/github.com/googleapis/java-storage/proto-google-cloud-storage-v2/src/main/java/com/google/storage/v2/BucketName.java:[137,11] incomparable types: com.google.storage.v2.Object and com.google.storage.v2.BucketName
    [ERROR] .../src/github.com/googleapis/java-storage/proto-google-cloud-storage-v2/src/main/java/com/google/storage/v2/BucketName.java:[140,33] incomparable types: java.lang.Class<capture#3 of ? extends com.google.storage.v2.BucketName> and java.lang.Class<capture#4 of ? extends com.google.storage.v2.Object>
    [ERROR] .../src/github.com/googleapis/java-storage/proto-google-cloud-storage-v2/src/main/java/com/google/storage/v2/BucketName.java:[141,39] incompatible types: com.google.storage.v2.Object cannot be converted to com.google.storage.v2.BucketName
    [ERROR] .../src/github.com/googleapis/java-storage/proto-google-cloud-storage-v2/src/main/java/com/google/storage/v2/ProjectName.java:[125,3] method does not override or implement a method from a supertype
    [ERROR] .../src/github.com/googleapis/java-storage/proto-google-cloud-storage-v2/src/main/java/com/google/storage/v2/ProjectName.java:[127,11] incomparable types: com.google.storage.v2.Object and com.google.storage.v2.ProjectName
    [ERROR] .../src/github.com/googleapis/java-storage/proto-google-cloud-storage-v2/src/main/java/com/google/storage/v2/ProjectName.java:[130,33] incomparable types: java.lang.Class<capture#5 of ? extends com.google.storage.v2.ProjectName> and java.lang.Class<capture#6 of ? extends com.google.storage.v2.Object>
    [ERROR] .../src/github.com/googleapis/java-storage/proto-google-cloud-storage-v2/src/main/java/com/google/storage/v2/ProjectName.java:[131,41] incompatible types: com.google.storage.v2.Object cannot be converted to com.google.storage.v2.ProjectName
    

BucketName, CryptoKeyName and ProjectName all implemented ResourceName and follow a different code generation path than the other proto classes. This different generation path does not use fully qualified class names for java.lang classes. This particular scenario is manifesting because GCS generate a class com.google.storage.v1.Object which takes resolution precedence to java.lang.Object and prevents java.lang.Object#equals(java.lang.Object) from being implemented.

As a temporary work around I'm manually applying a search and replace which can be seen here: https://github.com/googleapis/java-storage/blob/d6acdab54582852b3c14e152a12ea2f923ff85ef/synth.py#L40-L58

@BenWhitehead BenWhitehead added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. labels Jul 26, 2021
@miraleung
Copy link
Contributor

Using fully-qualified names for java.lang classes may make things less user-friendly or less readable, but we can fix the name collision for Object. Will look into this next week for FixIt.

@miraleung miraleung self-assigned this Jul 26, 2021
@BenWhitehead
Copy link
Contributor Author

It appears protobuf and gRPC exclusively uses fully qualified names (example https://github.com/googleapis/java-storage/pull/922/files#diff-2bb347d8e4f8109169ef2cd49aea4352494276e2264ceca7ecc9a5312c134847R308-R309). At my codes use site either short or fully qualified work equally well.

@miraleung miraleung removed the fixit label Jul 30, 2021
suztomo pushed a commit that referenced this issue Mar 21, 2023
suztomo added a commit that referenced this issue Mar 21, 2023
suztomo pushed a commit that referenced this issue Mar 21, 2023
🤖 I have created a release *beep* *boop*
---


## [2.6.0](googleapis/java-core@v2.5.11...v2.6.0) (2022-04-14)


### Features

* **java:** remove GoogleJsonClentFeature and OpenCensusFeature after relocation ([#793](googleapis/java-core#793)) ([cafd489](googleapis/java-core@cafd489))
* **java:** remove Netty Native Image configuration after relocation to gax ([#771](googleapis/java-core#771)) ([9cc7dba](googleapis/java-core@9cc7dba))
* **java:** remove protobuf Native Image configuration ([#784](googleapis/java-core#784)) ([7a8df66](googleapis/java-core@7a8df66))
* remove native-image.properties settings  after relocation ([#794](googleapis/java-core#794)) ([219a519](googleapis/java-core@219a519))
* remove resource-config after relocation ([#795](googleapis/java-core#795)) ([8ed3110](googleapis/java-core@8ed3110))
* remove substitutions after relocation to gax ([#789](googleapis/java-core#789)) ([85280b1](googleapis/java-core@85280b1))


### Bug Fixes

* **java:** register test class for reflection to fix native image test ([#766](googleapis/java-core#766)) ([fa07125](googleapis/java-core@fa07125))


### Dependencies

* revert protobuf to 3.19 and common-protos 2.8.3 ([#798](googleapis/java-core#798)) ([27ca70c](googleapis/java-core@27ca70c))
* update dependency com.google.api-client:google-api-client-bom to v1.34.0 ([#800](googleapis/java-core#800)) ([3abc47d](googleapis/java-core@3abc47d))
* update dependency com.google.api:gax-bom to v2.16.0 ([#785](googleapis/java-core#785)) ([bd33a76](googleapis/java-core@bd33a76))
* update dependency com.google.api.grpc:proto-google-common-protos to v2.8.1 ([#792](googleapis/java-core#792)) ([3f85e62](googleapis/java-core@3f85e62))
* update dependency com.google.api.grpc:proto-google-common-protos to v2.8.2 ([#796](googleapis/java-core#796)) ([d6ea18e](googleapis/java-core@d6ea18e))
* update dependency com.google.api.grpc:proto-google-iam-v1 to v1.3.0 ([#783](googleapis/java-core#783)) ([48594f3](googleapis/java-core@48594f3))
* update dependency com.google.api.grpc:proto-google-iam-v1 to v1.3.1 ([#799](googleapis/java-core#799)) ([9fe7d35](googleapis/java-core@9fe7d35))
* update dependency com.google.errorprone:error_prone_annotations to v2.12.1 ([#788](googleapis/java-core#788)) ([cfdabb4](googleapis/java-core@cfdabb4))
* update dependency com.google.http-client:google-http-client-bom to v1.41.6 ([#791](googleapis/java-core#791)) ([d9ff405](googleapis/java-core@d9ff405))
* update dependency com.google.http-client:google-http-client-bom to v1.41.7 ([#797](googleapis/java-core#797)) ([dfc3c57](googleapis/java-core@dfc3c57))
* update dependency com.google.protobuf:protobuf-bom to v3.20.0 ([#787](googleapis/java-core#787)) ([51f59fc](googleapis/java-core@51f59fc))
* update dependency io.grpc:grpc-bom to v1.45.1 ([#780](googleapis/java-core#780)) ([cd8a078](googleapis/java-core@cd8a078))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
2 participants