Skip to content

Setting the user-agent with a header provider in SpannerOptions fails #880

@thiagotnunes

Description

@thiagotnunes

Trying to set the user-agent with a header provider throws an IllegalArgumentException:

Exception in thread "main" java.lang.IllegalArgumentException: Multiple entries with same key: user-agent=test and user-agent=spanner-java/
	at com.google.common.collect.RegularImmutableMap.duplicateKeyException(RegularImmutableMap.java:181)
	at com.google.common.collect.RegularImmutableMap.createHashTable(RegularImmutableMap.java:120)
	at com.google.common.collect.RegularImmutableMap.create(RegularImmutableMap.java:81)
	at com.google.common.collect.ImmutableMap$Builder.build(ImmutableMap.java:355)
	at com.google.cloud.spanner.spi.v1.GapicSpannerRpc.<init>(GapicSpannerRpc.java:317)
	at com.google.cloud.spanner.SpannerOptions$DefaultSpannerRpcFactory.create(SpannerOptions.java:467)
	at com.google.cloud.spanner.SpannerOptions$DefaultSpannerRpcFactory.create(SpannerOptions.java:462)
	at com.google.cloud.ServiceOptions.getRpc(ServiceOptions.java:561)
	at com.google.cloud.spanner.SpannerOptions.getSpannerRpcV1(SpannerOptions.java:1169)
	at com.google.cloud.spanner.SpannerImpl.<init>(SpannerImpl.java:134)
	at com.google.cloud.spanner.SpannerOptions$DefaultSpannerFactory.create(SpannerOptions.java:457)
	at com.google.cloud.spanner.SpannerOptions$DefaultSpannerFactory.create(SpannerOptions.java:452)
	at com.google.cloud.ServiceOptions.getService(ServiceOptions.java:541)
	at com.google.cloud.spanner.Main.main(Main.java:40)

You can reproduce the error with the following code:

    final SpannerOptions options = SpannerOptions
        .newBuilder()
        .setHeaderProvider(FixedHeaderProvider.create("user-agent", "test"))
        .build();
    final Spanner spanner = options.getService();
    final DatabaseId id = DatabaseId.of(PROJECT, INSTANCE, DATABASE);
    final DatabaseClient databaseClient = spanner.getDatabaseClient(id);

    try (final ResultSet rs = databaseClient.singleUse().executeQuery(Statement.of("SELECT 1"))) {
      rs.next();
      System.out.println(rs.getLong(0));
    }

    spanner.close();

Metadata

Metadata

Assignees

Labels

api: spannerIssues related to the googleapis/java-spanner API.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions