[
https://issues.apache.org/jira/browse/XMLBEANS-559?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Andreas Beeker closed XMLBEANS-559.
-----------------------------------
> Race condition in SchemaIdentityConstraintImpl.java
> ---------------------------------------------------
>
> Key: XMLBEANS-559
> URL: https://issues.apache.org/jira/browse/XMLBEANS-559
> Project: XMLBeans
> Issue Type: Bug
> Affects Versions: Version 5.0.0
> Reporter: Thorsten Goetzke
> Assignee: PJ Fanning
> Priority: Major
> Fix For: Version 5.0.1
>
> Attachments: bugfix.java
>
>
> The race condition can lead to a rare exception in a multithreaded
> environment.
> The class uses two fields and initialises them lazy. The problem is that the
> process of initializing the field is not atomic, and simply declaring the
> fields volatile is not sufficient.
> As an example: Thread A enters getFieldPath(1).
> fieldPaths is is null so buildPaths happen.
> Thread A build the first Path (index 0). Then Thread A pauses and Thread B
> the methode getFieldPath(1)
> Thread B sees that _fieldPath is not null so it tries to access element 1,
> but that element was not build yet-> So Thread B gets null and bad things
> happen
> This issue has been around since basicly forever, I just never reported it.
> I will attach a fairly old source file wich I used to workaround this issue
> {code:java}
> private volatile XPath _selectorPath;
> private volatile XPath[] _fieldPaths; {code}
> {code}
> public Object getFieldPath(int index) {
> XPath[] p = _fieldPaths;
> if (p == null) {
> try {
> buildPaths();
> p = _fieldPaths;
> } catch (XPath.XPathCompileException e) {
> assert false : "Failed to compile xpath. Should be caught by
> compiler " + e;
> return null;
> }
> }
> return p[index];
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]