@@ -173,17 +173,19 @@ private void ensurePrintCoverage(final Env env) {
173
173
*/
174
174
private void printResults (final Env env ) {
175
175
final PrintStream printStream = new PrintStream (env .out ());
176
- for (Source source : sourceToNotYetCoveredSections .keySet ()) {
177
- final String path = source .getPath ();
178
- final int lineCount = source .getLineCount ();
179
- final List <Integer > notYetCoveredLineNumbers = notYetCoveredLineNumbers (source );
180
- final int notYetCoveredSize = notYetCoveredLineNumbers .size ();
181
- double coveredPercentage = 100 * ((double ) lineCount - notYetCoveredSize ) / lineCount ;
182
- printStream .println ("==" );
183
- printStream .println ("Coverage of " + path + " is " + String .format ("%.2f%%" , coveredPercentage ));
184
- printStream .println ("Lines not covered by execution:" );
185
- for (Integer notYetCoveredLineNumber : notYetCoveredLineNumbers ) {
186
- printStream .println (notYetCoveredLineNumber + " " + source .getCharacters (notYetCoveredLineNumber ));
176
+ synchronized (sourceToNotYetCoveredSections ) {
177
+ for (Source source : sourceToNotYetCoveredSections .keySet ()) {
178
+ final String path = source .getPath ();
179
+ final int lineCount = source .getLineCount ();
180
+ final List <Integer > notYetCoveredLineNumbers = notYetCoveredLineNumbers (source );
181
+ final int notYetCoveredSize = notYetCoveredLineNumbers .size ();
182
+ double coveredPercentage = 100 * ((double ) lineCount - notYetCoveredSize ) / lineCount ;
183
+ printStream .println ("==" );
184
+ printStream .println ("Coverage of " + path + " is " + String .format ("%.2f%%" , coveredPercentage ));
185
+ printStream .println ("Lines not covered by execution:" );
186
+ for (Integer notYetCoveredLineNumber : notYetCoveredLineNumbers ) {
187
+ printStream .println (notYetCoveredLineNumber + " " + source .getCharacters (notYetCoveredLineNumber ));
188
+ }
187
189
}
188
190
}
189
191
}
@@ -194,17 +196,19 @@ private void printResults(final Env env) {
194
196
* code in the given {@link Source}
195
197
*/
196
198
public List <Integer > notYetCoveredLineNumbers (final Source source ) {
197
- Set <SourceSection > sections = sourceToNotYetCoveredSections .get (source );
198
- Set <Integer > linesNotCovered = new HashSet <>();
199
- for (SourceSection ss : sections ) {
200
- for (int i = ss .getStartLine (); i <= ss .getEndLine (); i ++) {
201
- linesNotCovered .add (i );
199
+ synchronized (sourceToNotYetCoveredSections ) {
200
+ Set <SourceSection > sections = sourceToNotYetCoveredSections .get (source );
201
+ Set <Integer > linesNotCovered = new HashSet <>();
202
+ for (SourceSection ss : sections ) {
203
+ for (int i = ss .getStartLine (); i <= ss .getEndLine (); i ++) {
204
+ linesNotCovered .add (i );
205
+ }
202
206
}
207
+ List <Integer > sortedLines = new ArrayList (linesNotCovered .size ());
208
+ sortedLines .addAll (linesNotCovered );
209
+ sortedLines .sort (Integer ::compare );
210
+ return sortedLines ;
203
211
}
204
- List <Integer > sortedLines = new ArrayList (linesNotCovered .size ());
205
- sortedLines .addAll (linesNotCovered );
206
- sortedLines .sort (Integer ::compare );
207
- return sortedLines ;
208
212
}
209
213
210
214
/**
@@ -248,9 +252,11 @@ public void onLoad(LoadSourceSectionEvent event) {
248
252
final Source source = sourceSection .getSource ();
249
253
// TODO: This should not be necesery becuase of the filter. Bug!
250
254
if (!source .isInternal ()) {
251
- sourceToNotYetCoveredSections .computeIfAbsent (source , (Source s ) -> {
252
- return new HashSet <>();
253
- }).add (sourceSection );
255
+ synchronized (sourceToNotYetCoveredSections ) {
256
+ sourceToNotYetCoveredSections .computeIfAbsent (source , (Source s ) -> {
257
+ return new HashSet <>();
258
+ }).add (sourceSection );
259
+ }
254
260
}
255
261
}
256
262
}
@@ -344,7 +350,9 @@ public void onReturnValue(VirtualFrame vFrame, Object result) {
344
350
final Source source = instrumentedSourceSection .getSource ();
345
351
// TODO: This should not be necesery becuase of the filter. Bug!
346
352
if (!source .isInternal ()) {
347
- sourceToNotYetCoveredSections .get (source ).remove (instrumentedSourceSection );
353
+ synchronized (sourceToNotYetCoveredSections ) {
354
+ sourceToNotYetCoveredSections .get (source ).remove (instrumentedSourceSection );
355
+ }
348
356
}
349
357
}
350
358
}
0 commit comments