Skip to content

PubSub Awkward implementation of SubscriptionName::equals #1928

@HozahAled

Description

@HozahAled

Environment details

  1. Fedora 38
  2. Java version: 17.0.7
  3. version(s): proto-google-cloud-pubsub-v1-1.105.17.jar

Steps to reproduce

  1. Compare SubscriptionName to an object of another type

Code example

import com.google.pubsub.v1.SubscriptionName
import io.kotest.core.spec.style.WordSpec
import io.kotest.matchers.shouldBe

class PubSub:WordSpec({

    "equals" should{
        "not except when compared to an object of another class"{
            SubscriptionName.newBuilder().setSubscription("foo").setProject("bar").build().equals("foo") shouldBe false
        }
    }
})

Any additional information below

I'd imagine

if (o != null || getClass() == o.getClass()) {
https://github.com/googleapis/java-pubsub/blob/main/proto-google-cloud-pubsub-v1/src/main/java/com/google/pubsub/v1/SubscriptionName.java#L140

Should be replaced with

if (o != null && getClass() == o.getClass()) {

Though not an explicit breach of Object.equals' contract, I wouldn't expect any Object.equals override to throw an exception.

Metadata

Metadata

Assignees

Labels

api: pubsubIssues related to the Pub/Sub 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