palantir / palantir/conjure-java
Having an optional<any> generates an unchecked cast
Open
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 39
- Forks
- 49
- Avg merge
- 8h 22m
- Merged PRs (30d)
- 32
Description
What happened?
Defining an object like this:
MyObject:
fields:
myfield: optional<any>
Results in the following Java code:
@Generated("com.palantir.conjure.java.types.BeanBuilderGenerator")
@JsonIgnoreProperties(ignoreUnknown = true)
public static final class Builder {
...
@JsonSetter("detail")
public Builder detail(Optional<?> detail) {
this.detail =
(Optional<Object>) Preconditions.checkNotNull(detail, "detail cannot be null");
return this;
}
public Builder detail(Object detail) {
this.detail = Optional.of(Preconditions.checkNotNull(detail, "detail cannot be null"));
return this;
}
}
Where Optional<?> is cast into an Optional<Object>.
What did you want to happen?
public static final class Builder {
...
@JsonSetter("detail")
public Builder detail(Optional<Object> detail) {
this.detail = Preconditions.checkNotNull(detail, "detail cannot be null");
return this;
}
...
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the BeanBuilderGenerator named in the generated annotation and reproduce the optional example from the issue. Check the generated builder method for Optional<?> and verify that the result uses Optional without an unchecked cast; the Java output shown in the issue defines the expected behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100