mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 06:02:11 +02:00
Fix unhandled event loop exception when binary parser is not in plugin.xml
If a .cproject references a binary parser ID that is not in the plug-in XML, or in the XML, but marked as private, the UI cannot display the binary parsers and was raising an ArrayIndexOutOfBoundsException as below. This fix rewrites the array handling using collections. ```java !ENTRY org.eclipse.ui 4 0 2022-11-04 09:44:27.409 !MESSAGE Unhandled event loop exception !STACK 0 java.lang.ArrayIndexOutOfBoundsException: Index 7 out of bounds for length 7 at org.eclipse.cdt.ui.newui.BinaryParsTab.updateData(BinaryParsTab.java:253) at org.eclipse.cdt.ui.newui.AbstractCPropertyTab.setVisible(AbstractCPropertyTab.java:253) at org.eclipse.cdt.ui.newui.BinaryParsTab.setVisible(BinaryParsTab.java:221) at org.eclipse.cdt.ui.newui.AbstractCPropertyTab.handleTabEvent(AbstractCPropertyTab.java:630) at org.eclipse.cdt.ui.newui.AbstractPage.updateSelectedTab(AbstractPage.java:412) at org.eclipse.cdt.ui.newui.AbstractPage$4.widgetSelected(AbstractPage.java:382) ```
This commit is contained in:
parent
09e3b5ca29
commit
ac979bd9e1
1 changed files with 31 additions and 28 deletions
|
@ -13,9 +13,16 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.ui.newui;
|
package org.eclipse.cdt.ui.newui;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.model.CoreModelUtil;
|
import org.eclipse.cdt.core.model.CoreModelUtil;
|
||||||
|
@ -224,42 +231,38 @@ public class BinaryParsTab extends AbstractCPropertyTab {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateData(ICResourceDescription cfgd) {
|
public void updateData(ICResourceDescription cfgd) {
|
||||||
String[] ids = null;
|
Set<String> selectedIds = new LinkedHashSet<>();
|
||||||
if (page.isForPrefs()) { // prefs
|
if (page.isForPrefs()) { // prefs
|
||||||
if (cfgd != null && cfgd.getConfiguration() != null) {
|
if (cfgd != null && cfgd.getConfiguration() != null) {
|
||||||
tps = cfgd.getConfiguration().getTargetPlatformSetting();
|
tps = cfgd.getConfiguration().getTargetPlatformSetting();
|
||||||
if (tps != null)
|
if (tps != null) {
|
||||||
ids = tps.getBinaryParserIds();
|
String[] binaryParserIds = tps.getBinaryParserIds();
|
||||||
|
if (binaryParserIds != null) {
|
||||||
|
selectedIds.addAll(Arrays.asList(binaryParserIds));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (ids == null)
|
|
||||||
ids = new String[0]; // no selection
|
|
||||||
} else { // project
|
} else { // project
|
||||||
ICConfigurationDescription[] cfgs = page.getCfgsEditable();
|
ICConfigurationDescription[] cfgs = page.getCfgsEditable();
|
||||||
ids = CoreModelUtil.getBinaryParserIds(cfgs);
|
String[] binaryParserIds = CoreModelUtil.getBinaryParserIds(cfgs);
|
||||||
|
if (binaryParserIds != null) {
|
||||||
|
selectedIds.addAll(Arrays.asList(binaryParserIds));
|
||||||
}
|
}
|
||||||
Object[] data = new Object[configMap.size()];
|
|
||||||
HashMap<String, BinaryParserConfiguration> clone = new HashMap<>(configMap);
|
|
||||||
// add checked elements
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < ids.length; i++) {
|
|
||||||
data[i] = clone.get(ids[i]);
|
|
||||||
clone.remove(ids[i]);
|
|
||||||
}
|
}
|
||||||
// add remaining parsers (unchecked)
|
|
||||||
Iterator<String> it = clone.keySet().iterator();
|
List<BinaryParserConfiguration> selectedBinaryParsers = selectedIds.stream().map(configMap::get)
|
||||||
// i = 0;
|
.filter(Objects::nonNull).toList();
|
||||||
while (it.hasNext()) {
|
List<BinaryParserConfiguration> notSelectedBinaryParsers = configMap.entrySet().stream()
|
||||||
String s = it.next();
|
.filter(e -> !selectedIds.contains(e.getKey())).map(Entry::getValue).toList();
|
||||||
data[i++] = clone.get(s);
|
|
||||||
}
|
// Add the selected ones first so they are at the top of the list
|
||||||
tv.setInput(data);
|
List<BinaryParserConfiguration> allBinaryParsers = new ArrayList<>();
|
||||||
|
allBinaryParsers.addAll(selectedBinaryParsers);
|
||||||
|
allBinaryParsers.addAll(notSelectedBinaryParsers);
|
||||||
|
tv.setInput(allBinaryParsers.toArray());
|
||||||
|
|
||||||
tv.setAllChecked(false);
|
tv.setAllChecked(false);
|
||||||
// set check marks
|
selectedBinaryParsers.forEach(e -> tv.setChecked(e, true));
|
||||||
for (i = 0; i < ids.length; i++) {
|
|
||||||
if (configMap.containsKey(ids[i])) {
|
|
||||||
tv.setChecked(configMap.get(ids[i]), true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
updateButtons();
|
updateButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue