Make configuration variables thread safe
Brought to you by:
derrickoswald
There are various static fields that are used as configuration items to control the behaviour of the parser.
org.htmlparser.lexer.Lexer.STRICT_REMARKS
org.htmlparser.scanners.ScriptScanner.STRICT
org.htmlparser.scanners.ScriptDecoder.LAST_STATE
org.htmlparser.util.Translate.DECODE_LINE_BY_LINE
org.htmlparser.util.Translate.ENCODE_HEXADECIMAL
As they are static, this means that it is not possible to use different settings in different threads.
For example, it is not currently possible to use a STRICT scanner and a non-STRICT scanner in different threads (except perhaps by using different classloaders ...).
Logged In: YES
user_id=605407
Originator: NO
Not really a bug.
Change to Request For Enhancement.
Logged In: YES
user_id=1716708
Originator: YES
In order to use anything but the default configuration safely, all threads must use and set the same value.
If thread A sets STRICT=false, and thread B does not, then there is no guarantee that thread B will see the same value of STRICT throughout its lifetime. The Java memory model allows threads to cache values locally, so thread A may use its own copy of STRICT initially but then write it to main memory partway through thread B's operation.
It is admittedly unlikely, but it is permitted by the memory model as far as I understand it.