pulumi / pulumi/pulumi-java

Union including Any fails to compile

Open
#1,326 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area/codegen impact/accessibility kind/bug
Dominant language
Java
Stars
85
Forks
26
Avg merge
11h 49m
Merged PRs (30d)
22

Description

When generating a Java SDK with a property whose type is a Union<Any, something>, the builder methods are not compilable due to Java's erasure of generics at runtime.

This could possibly be addressed in this piece of code:
https://github.com/pulumi/pulumi-java/blob/f7468e19e755561d2a8770ebcc0374245c424b29/pkg/codegen/java/gen_program_expressions.go#L536

Schema
{
    "types": [
        "aws-native:iottwinmaker:EntityStatus": {
            "properties": {
                "error": {
                    "oneOf": [
                        {
                            "oneOf": [
                                {
                                    "$ref": "pulumi.json#/Any"
                                },
                                {
                                    "$ref": "pulumi.json#/Any"
                                }
                            ]
                        },
                        {
                            "$ref": "#/types/aws-native:iottwinmaker:EntityStatusErrorProperties"
                        }
                    ]
                },
            },
            "type": "object"
        }
    ]
}
Generated code
public final class EntityStatusArgs extends com.pulumi.resources.ResourceArgs {

    @Import(name="error")
    private @Nullable Output<Either<Output<Object>,EntityStatusErrorPropertiesArgs>> error;

    public static final class Builder {

        public Builder error(@Nullable Output<Either<Output<Object>,EntityStatusErrorPropertiesArgs>> error) {
            $.error = error;
            return this;
        }

        public Builder error(Either<Output<Object>,EntityStatusErrorPropertiesArgs> error) {
            return error(Output.of(error));
        }

        public Builder error(Output<Object> error) {
            return error(Either.ofLeft(error));
        }

        public Builder error(EntityStatusErrorPropertiesArgs error) {
            return error(Either.ofRight(error));
        }
    }
}
Compiler error
/home/runner/work/pulumi-aws-native/pulumi-aws-native/sdk/java/src/main/java/com/pulumi/awsnative/iottwinmaker/inputs/EntityStatusArgs.java:69: error: name clash: error(Output<Object>) and error(Output<Either<Output<Object>,EntityStatusErrorPropertiesArgs>>) have the same erasure
        public Builder error(Output<Object> error) {

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in pkg/codegen/java/gen_program_expressions.go around line 536 and compare the generated builder overloads shown in the issue. Reproduce the EntityStatus schema case and inspect the Java compiler's erasure error. Done means the generated SDK for a Union<Any, something> schema compiles without the conflicting overloads.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.