Skip to content

Commit

Permalink
Fix for usnistgov#46 debug counter not thread safe and counting in no…
Browse files Browse the repository at this point in the history
…n-debug mode
  • Loading branch information
vladimirralev committed Jan 24, 2019
1 parent 113ac33 commit 60a7e27
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/gov/nist/core/ParserCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
package gov.nist.core;

import java.text.ParseException;
import java.util.concurrent.atomic.AtomicInteger;

/** Generic parser class.
* All parsers inherit this class.
Expand All @@ -40,7 +41,7 @@
public abstract class ParserCore {
public static final boolean debug = Debug.parserDebug;

static volatile int nesting_level;
static AtomicInteger nesting_level;

protected LexerCore lexer;

Expand Down Expand Up @@ -99,7 +100,7 @@ protected NameValue nameValue(char separator) throws ParseException {

protected void dbg_enter(String rule) {
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < nesting_level ; i++)
for (int i = 0; i < nesting_level.get() ; i++)
stringBuilder.append(">");

if (debug) {
Expand All @@ -108,12 +109,12 @@ protected void dbg_enter(String rule) {
"\nlexer buffer = \n" +
lexer.getRest());
}
nesting_level++;
nesting_level.incrementAndGet();
}

protected void dbg_leave(String rule) {
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < nesting_level ; i++)
for (int i = 0; i < nesting_level.get() ; i++)
stringBuilder.append("<");

if (debug) {
Expand All @@ -123,7 +124,7 @@ protected void dbg_leave(String rule) {
"\nlexer buffer = \n" +
lexer.getRest());
}
nesting_level --;
nesting_level.decrementAndGet();
}

protected NameValue nameValue() throws ParseException {
Expand Down

0 comments on commit 60a7e27

Please sign in to comment.