[BUG] Java generator generates invalid code for int64 (long) fields with defaults
- Dominant language
- TypeScript
- Stars
- 448
- Forks
- 242
- Avg merge
- 15m
- Merged PRs (30d)
- 7
Description
### Describe the bug.
Optional int64 (long) fields with defaults break the Java code generation logic [here](https://github.com/asyncapi/modelina/blob/master/src/generators/java/JavaDefaultRendererUtil.ts):
```
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?
- [x] I checked and didn't find similar issue
### 🏢 Have you read the Contributing Guidelines?
- [x] I have read the [Contributing Guidelines](https://github.com/asyncapi/.github/blob/master/CONTRIBUTING.md)
### Are you willing to work on this issue ?
None
Contributor guide
Research direction
Start in src/generators/java/JavaDefaultRendererUtil.ts and reproduce the issue with the optional int64 field and default value shown in the report. Verify the generated Java source compiles and that the default is valid for the boxed Long type, while required int64 fields continue to behave correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100