Skip to content

convertion from string to enum fails #5691

Open
@nmesika-te

Description

@nmesika-te

Describe the bug

When issuing an ec2::DescribeNetworkInterfaces, the returned NetworkInterfaceType is a string that the sdk can convert to an Enum using an internal map. However, the value returned by the API for Nat Gateway does not match the value in the map. The result is that the Enum value returned does not correctly reflect the type of the interface (an "unknown to sdk" Enum value is returned)

Here are the returned values from services/ec2/src/main/resources/codegen-resources/service-2.json:46316:

    "NetworkInterfaceType":{
      "type":"string",
      "enum":[
        "interface",
        "natGateway",
        "efa",
        "trunk",
        "load_balancer",
        "network_load_balancer",
        "vpc_endpoint",
        "branch",
        "transit_gateway",
        "lambda",
        "quicksight",
        "global_accelerator_managed",
        "api_gateway_managed",
        "gateway_load_balancer",
        "gateway_load_balancer_endpoint",
        "iot_rules_managed",
        "aws_codestar_connections_managed"
      ]
    },

Note that natGateway is camel cased while the others use underscores.
Following is the the XML response from the AWS API for a specific interface. Note the last line <interfaceType>nat_gateway</interfaceType>

        <item>
            <networkInterfaceId>eni-0c712113537506cd7</networkInterfaceId>
            <subnetId>subnet-0a415aa89455cf4f8</subnetId>
            <vpcId>vpc-04f987fff6675ec10</vpcId>
            <availabilityZone>us-west-1a</availabilityZone>
            <description>Interface for NAT Gateway nat-06a39644e236c7926</description>
            <ownerId>036476006320</ownerId>
            <requesterId>213236389121</requesterId>
            <requesterManaged>true</requesterManaged>
            <status>in-use</status>
            <macAddress>06:c6:2a:ae:e4:23</macAddress>
            <privateIpAddress>10.56.5.210</privateIpAddress>
            <privateDnsName>ip-10-56-5-210.us-west-1.compute.internal</privateDnsName>
            <sourceDestCheck>false</sourceDestCheck>
            <groupSet/>
            <attachment>
                <attachmentId>ela-attach-fcc879c1</attachmentId>
                <instanceOwnerId>amazon-aws</instanceOwnerId>
                <deviceIndex>1</deviceIndex>
                <status>attached</status>
                <deleteOnTermination>false</deleteOnTermination>
            </attachment>
            <association>
                <publicIp>50.18.200.169</publicIp>
                <publicDnsName>ec2-50-18-200-169.us-west-1.compute.amazonaws.com</publicDnsName>
                <ipOwnerId>036476006320</ipOwnerId>
                <allocationId>eipalloc-0f749c8c6fe1d8101</allocationId>
                <associationId>eipassoc-a56ec57f</associationId>
                <natEnabled>true</natEnabled>
            </association>
            <tagSet/>
            <privateIpAddressesSet>
                <item>
                    <privateIpAddress>10.56.5.210</privateIpAddress>
                    <privateDnsName>ip-10-56-5-210.us-west-1.compute.internal</privateDnsName>
                    <primary>true</primary>
                    <association>
                        <publicIp>50.18.200.169</publicIp>
                        <publicDnsName>ec2-50-18-200-169.us-west-1.compute.amazonaws.com</publicDnsName>
                        <ipOwnerId>036476006320</ipOwnerId>
                        <allocationId>eipalloc-0f749c8c6fe1d8101</allocationId>
                        <associationId>eipassoc-a56ec57f</associationId>
                        <natEnabled>true</natEnabled>
                    </association>
                </item>
            </privateIpAddressesSet>
            <ipv6AddressesSet/>
            <interfaceType>nat_gateway</interfaceType>
        </item>

Expected Behavior

The Network Interface Type should resolve to NAT_GATEWAY.

Current Behavior

The Network Interface Type resolves to UNKNOWN_TO_SDK_VERSION

Reproduction Steps

        try(var client = Ec2Client.builder().build()) {
            var req = DescribeNetworkInterfacesRequest.builder().build();

            var resp = client.describeNetworkInterfaces(req);
            for(NetworkInterface nwif : resp.networkInterfaces()) {
                var ifType = nwif.interfaceType();
                var ifTypeName = nwif.interfaceTypeAsString();
                if (ifTypeName != null && ifTypeName.toLowerCase().contains("nat")) {
                    System.out.println(ifTypeName);
                    System.out.println(ifType);
                }
            }
        }

Response is:

nat_gateway
null

Indicating that the string internally stored by the SDK is nat_gateway and the convertion to Enum fails. This is due to the incorrect string defined here:

public enum NetworkInterfaceType {
    INTERFACE("interface"),
    NAT_GATEWAY("natGateway"),  <======= should be nat_gateway
    EFA("efa"),
    TRUNK("trunk"),
    LOAD_BALANCER("load_balancer"),
    NETWORK_LOAD_BALANCER("network_load_balancer"),
    VPC_ENDPOINT("vpc_endpoint"),
    BRANCH("branch"),
    TRANSIT_GATEWAY("transit_gateway"),
    LAMBDA("lambda"),
    QUICKSIGHT("quicksight"),
    GLOBAL_ACCELERATOR_MANAGED("global_accelerator_managed"),
    API_GATEWAY_MANAGED("api_gateway_managed"),
    GATEWAY_LOAD_BALANCER("gateway_load_balancer"),
    GATEWAY_LOAD_BALANCER_ENDPOINT("gateway_load_balancer_endpoint"),
    IOT_RULES_MANAGED("iot_rules_managed"),
    AWS_CODESTAR_CONNECTIONS_MANAGED("aws_codestar_connections_managed"),
    UNKNOWN_TO_SDK_VERSION((String)null);

    private static final Map<String, NetworkInterfaceType> VALUE_MAP = EnumUtils.uniqueIndex(NetworkInterfaceType.class, NetworkInterfaceType::toString);

Possible Solution

Update services/ec2/src/main/resources/codegen-resources/service-2.json:46316 to replace "natGateway"with"nat_gateway"`.

Additional Information/Context

No response

AWS Java SDK version used

2.26.18

JDK version used

openjdk version "17.0.9" 2023-10-17

Operating System and version

Linux 5.10.219-208.866.amzn2.x86_64 #1 SMP Tue Jun 18 14:00:06 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Metadata

Metadata

Assignees

Labels

bugThis issue is a bug.service-apiThis issue is due to a problem in a service API, not the SDK implementation.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions