Skip to content

Commit 8f2ab8a

Browse files
committed
Merge branch 'fix-intellij'
This changes the indexer to use a ConcurrentSkipListMap rather than a TreeMap, to avoid a compilation issue when using IntelliJ. It also adds more debugging information for the AbstractIndexWriter and Reader to show which annotation causes an exception to occur so debugging can be done more easily. Closes issues #136 and #140.
2 parents 49228d7 + 92bcea3 commit 8f2ab8a

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/main/java/org/scijava/annotations/AbstractIndexWriter.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.util.Map;
4545
import java.util.Map.Entry;
4646
import java.util.TreeMap;
47+
import java.util.concurrent.ConcurrentSkipListMap;
4748

4849
import javax.lang.model.element.AnnotationValue;
4950

@@ -60,7 +61,7 @@
6061
public abstract class AbstractIndexWriter {
6162

6263
private final Map<String, Map<String, Object>> map =
63-
new TreeMap<String, Map<String, Object>>();
64+
new ConcurrentSkipListMap<String, Map<String, Object>>();
6465

6566
protected synchronized boolean foundAnnotations() {
6667
return !map.isEmpty();
@@ -137,7 +138,8 @@ protected synchronized void merge(final String annotationName,
137138
int changedCount = map.size();
138139
boolean hasObsoletes = false;
139140

140-
final IndexReader reader = new IndexReader(in);
141+
final IndexReader reader =
142+
new IndexReader(in, annotationName + " from " + in);
141143
try {
142144
for (;;) {
143145
@SuppressWarnings("unchecked")

src/main/java/org/scijava/annotations/IndexReader.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,17 @@
6464
class IndexReader {
6565

6666
private final PushbackInputStream in;
67+
private final String originalISName;
6768

6869
IndexReader(final InputStream in) {
70+
this(in, "");
71+
}
72+
73+
IndexReader(final InputStream in, final String isName) {
6974
this.in =
7075
in instanceof PushbackInputStream ? (PushbackInputStream) in
7176
: new PushbackInputStream(new BufferedInputStream(in));
77+
this.originalISName = isName;
7278
}
7379

7480
public Object next() throws IOException {
@@ -155,7 +161,8 @@ else if (c < '0' || c > '9') {
155161
if (c == '"') {
156162
return readString();
157163
}
158-
throw new IOException("Unexpected char: '" + (char) c + "'");
164+
throw new IOException("Unexpected char: '" + (char) c + "'"+
165+
((originalISName.length()>0) ? " from "+originalISName : ""));
159166
}
160167

161168
public void close() throws IOException {
@@ -206,7 +213,7 @@ private int expect(char a, char b) throws IOException {
206213
return 1;
207214
}
208215
throw new IOException("Expected '" + a + "' or '" + b + "', got '" +
209-
(char) c + "'");
216+
(char) c + "'"+((originalISName.length()>0) ? " from "+originalISName : ""));
210217
}
211218

212219
private void expect(String match) throws IOException {
@@ -217,6 +224,7 @@ private void expect(String match) throws IOException {
217224

218225
private IndexReader() {
219226
this.in = null;
227+
this.originalISName="";
220228
}
221229

222230
static IndexReader getLegacyReader(final InputStream in) throws IOException {

0 commit comments

Comments
 (0)