Skip to content

Commit a76717b

Browse files
committed
improve doc and catch possible exception
1 parent 70f1c25 commit a76717b

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/main/java/org/cryptomator/linux/quickaccess/DolphinPlaces.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,26 @@ public String removeEntryFromConfig(String config) throws QuickAccessServiceExce
106106
var contentToWrite2 = part2Tmp[part2Tmp.length - 1];
107107

108108
return contentToWrite1 + "\n" + contentToWrite2;
109-
} catch (IOException | SAXException e) {
109+
} catch (IOException | SAXException | IllegalStateException e) {
110110
throw new QuickAccessServiceException("Removing entry from KDE places file failed.", e);
111111
}
112112
}
113113

114+
/**
115+
* Returns the start index (inclusive) of the {@link DolphinPlaces#ENTRY_TEMPLATE} entry
116+
* @param placesContent the content of the XBEL places file
117+
* @param idIndex start index (inclusive) of the entrys id tag value
118+
* @return start index of the first bookmark tag, searching backwards from idIndex
119+
*/
114120
private int indexOfEntryOpeningTag(String placesContent, int idIndex) {
115121
var xmlWhitespaceChars = List.of(' ', '\t', '\n');
116122
for (char c : xmlWhitespaceChars) {
117-
int idx = placesContent.lastIndexOf("<bookmark" + c, idIndex);
123+
int idx = placesContent.lastIndexOf("<bookmark" + c, idIndex); //with the whitespace we ensure, that no tags starting with "bookmark" (e.g. bookmarkz) are selected
118124
if (idx != -1) {
119125
return idx;
120126
}
121127
}
122-
throw new IllegalStateException("File " + PLACES_FILE + " is valid xbel file, but does not contain opening bookmark tag.");
128+
throw new IllegalStateException("Found entry id " + id + " in " + PLACES_FILE + ", but it is not a child of <bookmark> tag.");
123129
}
124130
}
125131

0 commit comments

Comments
 (0)