Skip to content

[BUG] Java generator generates invalid code for int64 (long) fields with defaults #2406

@carlturnerfs

Description

@carlturnerfs

Describe the bug.

Optional int64 (long) fields with defaults break the Java code generation logic here:

  potentiallyBigNumber:
    type: integer
    format: int64
    default: 2

leads to code like

private Long potentiallyBigNumber = 2;

which is invalid Java, leading to errors like

incompatible types: int cannot be converted to java.lang.Long

(Note that required fields with defaults [which don't actually made sense] work okay since they are generated as the unboxed long type and then Java automatically converts the integer constant to a long.)

(Note that the linked file isn't ideal in other ways, e.g. it doesn't escape String defaults, but that's probably a separate issue.)

Expected behavior

Should create compilable Java code. Could be e.g. 2L.

Screenshots

N/A

How to Reproduce

Create API spec as above; run modelina Java generation; try to compile resulting Java.

🖥️ Device Information [optional]

N/A

👀 Have you checked for similar open issues?

  • I checked and didn't find similar issue

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue ?

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstale

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions