| Summary: | [xtend] problem with auto-converting lists to arrays | ||
|---|---|---|---|
| Product: | [Modeling] TMF | Reporter: | Moritz Eysholdt <moritz.eysholdt> |
| Component: | Xtext | Assignee: | Project Inbox <tmf.xtext-inbox> |
| Status: | CLOSED FIXED | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | mail, sebastian.zarnekow |
| Version: | unspecified | Flags: | sebastian.zarnekow:
indigo+
|
| Target Milestone: | SR2 | ||
| Hardware: | PC | ||
| OS: | Mac OS X - Carbon (unsup.) | ||
| Whiteboard: | |||
false positive for the workaround:
---
override getExportedPackagesRt(Grammar grammar) {
return newArrayList(semanticSequencer.packageName) as List<String>
}
---
compiles to
---
public String[] getExportedPackagesRt(final Grammar grammar) {
String _packageName = this.semanticSequencer.getPackageName();
ArrayList<String> _newArrayList = CollectionLiterals.<String>newArrayList(_packageName);
return ((String[])Conversions.unwrapArray(((List<String>) _newArrayList)));
}
---
which throws the following exception at runtime:
---
java.lang.ClassCastException: java.util.ArrayList
at org.eclipse.xtext.generator.serializer.SerializerFragment.getExportedPackagesRt(SerializerFragment.java:122)
---
line 122 is:
---
return ((String[])Conversions.unwrapArray(((List<String>) _newArrayList)));
---
We know the element type of the list and the expected array type statically. That's why we can pass this information to the conversion method (which could take a second parameter of type class which could be used to instantiate the array). Pushed to master. Closing all bugs that were set to RESOLVED before Neon.0 Closing all bugs that were set to RESOLVED before Neon.0 |
when overriding the Java Method --- public String[] getExportedPackagesRt(Grammar grammar) --- then --- override getExportedPackagesRt(Grammar grammar) { return newArrayList(semanticSequencer.packageName) } --- raises the error "Incompatible types. Expected java.lang.String[] or java.util.List<java.lang.String> but was java.util.ArrayList<java.lang.String>" workaround: type-cast to List<String> --- override getExportedPackagesRt(Grammar grammar) { return newArrayList(semanticSequencer.packageName) as List<String> } --- Expected behavior: flawlessly convert all sub-types of List<String>