-
Notifications
You must be signed in to change notification settings - Fork 52
Issue with Parameter
of type array with generics wildcard vs raw type
#415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @NicoKiaru, I don't really have an answer, but I tried to make a minimal example. It prints the field type and the output of
This is the output:
|
I would prefer to fix this on the SJC side, but I won't have time to work on it for at least a few weeks. But I appreciate the detailed bug report and analysis, @NicoKiaru! Thank you. And thank you @frauzufall for attempting to create an MCVE! |
I've added a (currently failing) test which reproduces the error in the PR #416. I'm not sure it can be more minimal. Also I noticed that I can overcome this issue by assigning a higher priority to the converter I'd like to use, but still, scijava should not try to put a File array into another sort of array, so it's still worth investigating. |
I tried to add a really minimal test here: #417 It seems the issue is in the private implementation of |
There are some weird things happening with arrays and generics. I can't find it again, but there was an explanation of the reason why an object of class |
Also add minimal test for array types with generics. See #415
Also add minimal test for array types with generics. See #415
Also add minimal test for array types with generics. See #415
Closed in f6d8749 |
Hi,
I noticed a strange behaviour with scijava parameters. It looks like the handling of array parameters are very different if they contain a generics wildcard or not:
Let's imagine a class:
And a scijava converter from
String
toMyClass<?>[]
(not sure the wildcard changes anything if present in the converter)This:
behaves correctly with regards to the scijava mechanism. The correct converter is called.
However this:
completely fails : in the test case I have, the scijava mechanism attempts to put a
File[]
object intomyobjects
, obviously failing.I narrowed down the issue to the
CommandModuleItem
class. The linescijava-common/src/main/java/org/scijava/command/CommandModuleItem.java
Line 76 in afe795a
[L MyClass
, while if it has a generics widlcard, this same line returns[L Object
, wrongfully allowing irrelevant converters (thus the one from String to File array).I have not made a minimal example of this issue, but one test in
bigdataviewer-playground
can be used to reproduce the issue : https://github.com/bigdataviewer/bigdataviewer-playground/blob/fixes-rawtype/src/test/src/sc/fiji/bdvpg/scijava/ScijavaShowDemo.java.The demo fails. But if you remove the wildcard in the line https://github.com/bigdataviewer/bigdataviewer-playground/blob/daab0a336831b89c44d13932c243dd41e493dbe5/src/main/java/sc/fiji/bdvpg/scijava/command/bdv/BdvSourcesAdderCommand.java#L49:
SourceAndConverter[] sacs;
Then everything works.
How can this be solved ? I'm also open to suggestions on my code. I tend to fear that modifying scijava common is risky. So if there's a solution on
bigdataviewer-playground
side I would rather do it. I can think of 3 options:List
+ we are not supposed to use raw types in Java as far as I understoodcontainer
class :SourceAndConverterList
which would hold a single fieldList<SourceAndConverter>
. This seems the most easy thing to do a provides a lot of control on the scijava side - but it's a bit inelegantList<SourceAndConverter<?>>
scijava parameter, but I have no idea if this is possible. To me, because the generic types are erased at runtime, this looks impossible, but is it really ?Here's some maybe related issues:
#172
#118
The text was updated successfully, but these errors were encountered: