Uh oh!
There was an error while loading. Please reload this page.
ParameterValue.toXYZ() returns Object instead of primitive got numeric, boolean, chart - #208
ParameterValue.toXYZ() returns Object instead of primitive got numeric, boolean, chart#208decebals wants to merge 1 commit into
Conversation
gitblit
commented
Aug 18, 2015
I think this will break some (all?) existing apps that use controllers with primitive types. publicvoidgetItems(intpage, intsize, booleanincludeMetadata) {
}In the above example we'll get |
decebals
commented
Nov 28, 2015
I have the same problem in if (getSettings().getWorkerThreads() > 0) {
builder.setWorkerThreads(getSettings().getWorkerThreads());
}I prefer this construction: if (getSettings().getWorkerThreads() != null) {
// I am sure that "workerThreads" doesn't exist in settings
...
}It's a little tricky to assign a default value for a null (missing) parameter/setting. From my point of view the code is more clean with object (Integer, Boolean) instead of primitives.
Sure, I see this thing and it's a problem for controllers. I don't know is it's not possible to make a compromise for controllers (the idea is to use |
gitblit
commented
Nov 29, 2015
I'd really prefer not to lose the simplicity of primitive values. Your proposed syntax: Longid = routeContext.getParameter("id").toLong();
// id is null if the parameter value is null or emptyif (id != null) {
// do my job
}My syntax counter-proposal: Longid = null;
if (routeContext.hasParameter("id")) { // empty value is acceptableid = routeContext.getParameter("id").toLong(); // primitive auto-boxed to object
}
// ORif (routeContext.hasParameterValue("id")) { // empty value is not acceptableid = routeContext.getParameter("id").toLong(); // primitive auto-boxed to object
}
if (id != null) {
// do my job
}Looks like we need to fixup things like
Interesting. I have the exact opposite opinion. When reviewing code a deeper understanding of runtime behavior is required when you use the object peers of primitives and you introduce more surface area for NPEs. Switching to objects also adds value sanity checks in addition to normal range checks: if (getSettings().getWorkerThreads() != null) {
// I am sure that "workerThreads" doesn't exist in settings if (getSettings().getWorkerThreads() > 0) {
// you can't assign 0 (or fewer) worker threads
...
}
} |
My goal is to simplify the parameter value read process for null or empty values.
Before this PR:
The problems with last snippet are:
isNull()from checkif (isNull()) { return defaultValue; }with a more comprehensiveisNullOrEmpty()With current PR we can write:
For my tests this PR does't not affect existing applications built with Pippo.
What do you think, brings value or not this PR?