question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PropertyDefinition.getType() silently converts primitive class to its boxed counterpart

See original GitHub issue

Description

I’d expect PropertyDefinition.getType() to return the actual type of the field (e.g. int.class) and not the boxed counterpart (Integer.class). Please either make getType() return the actual type, or document that it will return the class of the boxed counterpart (+provide a function named getActualType() that returns the original type, e.g. primitive int.class).

Expected outcome

Minimal reproducible example

Steps to reproduce

Environment

Vaadin version(s): 14.8.11 OS: Windows

Browsers

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mvysnycommented, Jun 22, 2022

Thank you Leif. My use-case: calculating default values. The default value of int.class is 0 while of Integer.class is null. I was building a FilterBar showing closable filter “pills” for filter fields with different than the default value.

Screenshot from 2022-06-22 13-56-51

In this example, the “Active Only” filter bean is primitive boolean with the default value of false; the FilterBar only displays the “Active Only” “pill” when it’s different from the default value, which in this case is false. For booleans it probably doesn’t make much sense (3-state vs 2-state boolean logic is not a sound example 😄 ) but it makes much more sense for, say, int.class.

Note the red cross button which resets the filter to the default value, which is null for Objects but a non-null value for primitives. I was using the PropertyDefinition API to figure out the default value and setting nulls via reflection, which gave me exceptions… hence the issue.

1reaction
DiegoCardosocommented, Jun 16, 2022

Sorry, can we move this to vaadin/flow?

Done.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Autoboxing and Unboxing
Autoboxing is the automatic conversion that the Java compiler makes between the primitive types and their corresponding object wrapper classes.
Read more >
Groovy Language Documentation
Automatic boxing and unboxing occur when, for instance, calling a method requiring the wrapper class and passing it a primitive variable as the...
Read more >
How To Test if Type is Primitive - Stack Overflow
This was the result of my query: Type contextType = context.GetType(); var props = (from property in contextType.GetProperties() let name ...
Read more >
Index (XStream Core 1.4.11.1 API) - Javadoc.io
Converts a byte primitive or java.lang.Byte wrapper to a String. ByteConverter() - Constructor for class com.thoughtworks.xstream.converters.basic.
Read more >
Index (Guava: Google Core Libraries for Java 23.3-android API)
This class provides a skeletal implementation of the Cache interface to minimize ... Returns a Converter that converts values using bimap.get() , and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found