Skip to content

Conversation

gsmet
Copy link
Member

@gsmet gsmet commented Apr 25, 2025

Fixes #47478

@gsmet gsmet force-pushed the better-handle-basic-types branch from 4f79ea1 to ab8d361 Compare April 25, 2025 16:10
Comment on lines +27 to +32
static boolean isBoxedPrimitive(String typeName) {
return "java.lang.Character".equals(typeName) || "java.lang.Short".equals(typeName)
|| "java.lang.Integer".equals(typeName) || "java.lang.Long".equals(typeName)
|| "java.lang.Float".equals(typeName) || "java.lang.Double".equals(typeName)
|| "java.lang.Boolean".equals(typeName);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ladicek I was wondering if we should have a util in Jandex for this. I couldn't find one but maybe there is one?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have one, but it makes sense. I'll add PrimitiveType.isBox(Type) in the next version.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏽

That could probably be used in a lot of places.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ladicek awesome!

Comment on lines +48 to +64
static ResultHandle getDefaultValue(BytecodeCreator bytecodeCreator, Type type) {
if (type.kind() != Kind.PRIMITIVE) {
return bytecodeCreator.loadNull();
}

return switch (type.name().toString()) {
case "byte" -> bytecodeCreator.load(DEFAULT_BYTE);
case "boolean" -> bytecodeCreator.load(DEFAULT_BOOLEAN);
case "char" -> bytecodeCreator.load(DEFAULT_CHAR);
case "double" -> bytecodeCreator.load(DEFAULT_DOUBLE);
case "float" -> bytecodeCreator.load(DEFAULT_FLOAT);
case "int" -> bytecodeCreator.load(DEFAULT_INT);
case "long" -> bytecodeCreator.load(DEFAULT_LONG);
case "short" -> bytecodeCreator.load(DEFAULT_SHORT);
default -> throw new IllegalStateException("Type " + type + " should be handled by the switch");
};
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ladicek do you see a better way to handle that? I need to assign a value to the ResultHandle, including for primitive types and I ended up with this but I was wondering if there was a better way to handle that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we have a method to load a default value based on given type. What you have is close to the best. (I'd personally avoid the static fields and just pass (byte) 0, false, '\0', 0.0, 0.0F, 0, 0L, (short) 0, but there's almost zero difference.)

(I actually think we don't have that in Gizmo 2 either. I'll make sure we add it, because it makes sense.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ladicek yes, Gizmo 2 is exactly where I expected this to go. I thought it was useful input from real world usage.

@gsmet
Copy link
Member Author

gsmet commented Apr 25, 2025

/cc @mariofusco

Copy link

quarkus-bot bot commented Apr 25, 2025

Status for workflow Quarkus CI

This is the status report for running Quarkus CI on commit ab8d361.

✅ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

You can consult the Develocity build scans.

Copy link
Contributor

@mariofusco mariofusco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job, thank you!

@gsmet gsmet merged commit 6162d4a into quarkusio:main Apr 28, 2025
39 checks passed
@quarkus-bot quarkus-bot bot added this to the 3.23 - main milestone Apr 28, 2025
@gsmet gsmet modified the milestones: 3.23 - main, 3.22.1 Apr 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

VerifyError when using Float in Model deserialized by Jackson
4 participants