Skip to content
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

Fix unhandled event loop exception when binary parser is not in plugin.xml #137

Merged
merged 1 commit into from
Nov 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@
*******************************************************************************/
package org.eclipse.cdt.ui.newui;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
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.model.CoreModelUtil;
Expand Down Expand Up @@ -224,42 +231,38 @@ public void setVisible(boolean _visible) {

@Override
public void updateData(ICResourceDescription cfgd) {
String[] ids = null;
Set<String> selectedIds = new LinkedHashSet<>();
if (page.isForPrefs()) { // prefs
if (cfgd != null && cfgd.getConfiguration() != null) {
tps = cfgd.getConfiguration().getTargetPlatformSetting();
if (tps != null)
ids = tps.getBinaryParserIds();
if (tps != null) {
String[] binaryParserIds = tps.getBinaryParserIds();
if (binaryParserIds != null) {
selectedIds.addAll(Arrays.asList(binaryParserIds));
}
}
}
if (ids == null)
ids = new String[0]; // no selection
} else { // project
ICConfigurationDescription[] cfgs = page.getCfgsEditable();
ids = CoreModelUtil.getBinaryParserIds(cfgs);
}
Object[] data = new Object[configMap.size()];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key error is that size of data was wrong, it assumed that it needed to be the size of all plugin.xml defined binary parsers. It didn't account for ids having other ids, so the i variable below would be over incremented.

All this is solved by removing hard coded array sizes.

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();
// i = 0;
while (it.hasNext()) {
String s = it.next();
data[i++] = clone.get(s);
}
tv.setInput(data);
tv.setAllChecked(false);
// set check marks
for (i = 0; i < ids.length; i++) {
if (configMap.containsKey(ids[i])) {
tv.setChecked(configMap.get(ids[i]), true);
String[] binaryParserIds = CoreModelUtil.getBinaryParserIds(cfgs);
if (binaryParserIds != null) {
selectedIds.addAll(Arrays.asList(binaryParserIds));
}
}

List<BinaryParserConfiguration> selectedBinaryParsers = selectedIds.stream().map(configMap::get)
.filter(Objects::nonNull).toList();
List<BinaryParserConfiguration> notSelectedBinaryParsers = configMap.entrySet().stream()
.filter(e -> !selectedIds.contains(e.getKey())).map(Entry::getValue).toList();

// Add the selected ones first so they are at the top of the list
List<BinaryParserConfiguration> allBinaryParsers = new ArrayList<>();
allBinaryParsers.addAll(selectedBinaryParsers);
allBinaryParsers.addAll(notSelectedBinaryParsers);
tv.setInput(allBinaryParsers.toArray());

tv.setAllChecked(false);
selectedBinaryParsers.forEach(e -> tv.setChecked(e, true));
updateButtons();
}

Expand Down