Skip to content
Snippets Groups Projects
Commit af245bf0 authored by Simon Barner's avatar Simon Barner
Browse files

Storage: Improve error message for duplicated/missing IDs

* Print list of all affected elements
* Indicate if it ID was missing or duplicated

Issue-Ref: 3459
Issue-Url: https://af3-developer.fortiss.org/issues/3459



Signed-off-by: default avatarSimon Barner <barner@fortiss.org>
parent 6d4207ed
No related branches found
No related tags found
1 merge request!83459 check i ds avoid duplicate save
AutoUndoCommandStack.java 6aa645a9ed6e6547539c376fda97284928c4f9d4 GREEN AutoUndoCommandStack.java 6aa645a9ed6e6547539c376fda97284928c4f9d4 GREEN
EMFTransactionalCommand.java ba4b5bead9768b6ce6c955b9238cd96cb722533c GREEN EMFTransactionalCommand.java ba4b5bead9768b6ce6c955b9238cd96cb722533c GREEN
EclipseResourceStorageService.java 1b9722e31a5ec33e4c3f7bb171fc2ce587729bf8 GREEN EclipseResourceStorageService.java 1b9722e31a5ec33e4c3f7bb171fc2ce587729bf8 GREEN
ModelContext.java 0510b23ced1fc381a43d5e45437ba6558b5d3301 YELLOW ModelContext.java 220944231c0e036f29d4911d2658c33b2427b09f YELLOW
NonDirtyingEMFTransactionalCommand.java ec5f282603891096b09f2628155dd27e3a21c588 GREEN NonDirtyingEMFTransactionalCommand.java ec5f282603891096b09f2628155dd27e3a21c588 GREEN
...@@ -34,6 +34,7 @@ import java.util.Iterator; ...@@ -34,6 +34,7 @@ import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
...@@ -202,22 +203,22 @@ class ModelContext implements ITopLevelElement, CommandStackListener { ...@@ -202,22 +203,22 @@ class ModelContext implements ITopLevelElement, CommandStackListener {
private boolean checkIDs() { private boolean checkIDs() {
Set<Integer> ids = new HashSet<Integer>(); Set<Integer> ids = new HashSet<Integer>();
boolean hadMissing = false; // Store String representation of element with duplicated IDs before fixing it
boolean hadDuplicates = false; Map<String, Integer> objWithIdProblem = new HashMap<String, Integer>();
for(Iterator<EObject> i = getRootModelElement().eAllContents(); i.hasNext();) { for(Iterator<EObject> i = getRootModelElement().eAllContents(); i.hasNext();) {
EObject eo = i.next(); EObject eo = i.next();
if(eo instanceof IIdLabeled) { if(eo instanceof IIdLabeled) {
final IIdLabeled element = (IIdLabeled)eo; final IIdLabeled element = (IIdLabeled)eo;
int id = element.getId(); int id = element.getId();
if(id <= 0) { if(id <= 0) {
hadMissing = true; objWithIdProblem.put(element.toString(), null);
} else { } else {
// Reset duplicate IDs. They will be regenerated together with missing IDs. This // Reset duplicate IDs. They will be regenerated together with missing IDs. This
// is a safe operation since at this stage, references are still based on Java // is a safe operation since at this stage, references are still based on Java
// references. Only in the persisted resource, references will be based on IDs, // references. Only in the persisted resource, references will be based on IDs,
// which is why special care must be taken to ensure uniqueness. // which is why special care must be taken to ensure uniqueness.
if(ids.contains(id)) { if(ids.contains(id)) {
hadDuplicates = true; objWithIdProblem.put(element.toString(), element.getId());
runAsNonDirtyingCommand(() -> { runAsNonDirtyingCommand(() -> {
element.setId(0); element.setId(0);
}); });
...@@ -231,18 +232,27 @@ class ModelContext implements ITopLevelElement, CommandStackListener { ...@@ -231,18 +232,27 @@ class ModelContext implements ITopLevelElement, CommandStackListener {
maxId = max(0, maxId); maxId = max(0, maxId);
if(hadMissing || hadDuplicates) { if(!objWithIdProblem.isEmpty()) {
runAsNonDirtyingCommand(() -> { runAsNonDirtyingCommand(() -> {
maxId = generateMissingIDs(getRootModelElement(), maxId); maxId = generateMissingIDs(getRootModelElement(), maxId);
}); });
if(hadDuplicates) { String msg = "The following missing/duplicate IDs have been fixed in \"";
String msg = "Duplicate IDs have been removed from \""; msg += resource.getURI().lastSegment() + "\".\n";
msg += resource.getURI().lastSegment() + "\". "; msg += "Please report this incident since it indicates a programming error ";
msg += msg += "that could result in corrupted model files.\n";
"Please report this incident since it could result in corrupted model files."; for(Entry<String, Integer> entry : objWithIdProblem.entrySet()) {
error(ToolingKernelActivator.getDefault(), msg); Integer id = entry.getValue();
if(id == null) {
msg += " Missing ID added to ";
} else {
msg += " Duplicate ID " + id + " disambiguated for ";
}
String name = entry.getKey();
msg += "element \"" + name + "\"\n";
} }
error(ToolingKernelActivator.getDefault(), msg);
return true; return true;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment