[ https://issues.apache.org/jira/browse/XMLBEANS-559?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17310100#comment-17310100 ]
PJ Fanning commented on XMLBEANS-559: ------------------------------------- Thanks - applied change usingĀ https://github.com/apache/xmlbeans/commit/8e8c674ed21f44fa51c8d2a5f1bb5262a26e1b05 > 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 > 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: dev-unsubscr...@poi.apache.org For additional commands, e-mail: dev-h...@poi.apache.org