Project

Profile

Help

Revision 5864acf7

Added by Michael Kay about 13 years ago

Fix bug 2152858 - multithreading with keys

View differences:

latest9.1/bj/net/sf/saxon/trans/KeyManager.java
479 479

  
480 480
        int keySetNumber = keySet.getKeySetNumber();
481 481
        BuiltInAtomicType itemType = value.getPrimitiveType();
482
        Object indexObject = getIndex(doc, keySetNumber, itemType);
483
        if (indexObject instanceof String) {
484
            // index is under construction
485
            XPathException de = new XPathException("Key definition is circular");
486
            de.setXPathContext(context);
487
            de.setErrorCode("XTDE0640");
488
            throw de;
489
        }
490
        HashMap index = (HashMap)indexObject;
491

  
492
        // If the index does not yet exist, then create it.
493
        if (index==null) {
494
            // Mark the index as being under construction, in case the definition is circular
495
            putIndex(doc, keySetNumber, itemType, "Under Construction", context);
496
            index = buildIndex(keySet, itemType, foundItemTypes, doc, context);
497
            putIndex(doc, keySetNumber, itemType, index, context);
498
            if (foundItemTypes != null) {
499
                // build indexes for each item type actually found
500
                for (Iterator f = foundItemTypes.iterator(); f.hasNext();) {
501
                    BuiltInAtomicType t = (BuiltInAtomicType)f.next();
502
                    if (!t.equals(BuiltInAtomicType.STRING)) {
503
                        putIndex(doc, keySetNumber, t, "Under Construction", context);
504
                        index = buildIndex(keySet, t, null, doc, context);
505
                        putIndex(doc, keySetNumber, t, index, context);
482
        HashMap index;
483
        synchronized(doc) {
484
            Object indexObject = getIndex(doc, keySetNumber, itemType);
485
            if (indexObject instanceof String) {
486
                // index is under construction
487
                XPathException de = new XPathException("Key definition is circular");
488
                de.setXPathContext(context);
489
                de.setErrorCode("XTDE0640");
490
                throw de;
491
            }
492
            index = (HashMap)indexObject;
493

  
494
            // If the index does not yet exist, then create it.
495
            if (index==null) {
496
                // Mark the index as being under construction, in case the definition is circular
497
                putIndex(doc, keySetNumber, itemType, "Under Construction", context);
498
                index = buildIndex(keySet, itemType, foundItemTypes, doc, context);
499
                putIndex(doc, keySetNumber, itemType, index, context);
500
                if (foundItemTypes != null) {
501
                    // build indexes for each item type actually found
502
                    for (Iterator f = foundItemTypes.iterator(); f.hasNext();) {
503
                        BuiltInAtomicType t = (BuiltInAtomicType)f.next();
504
                        if (!t.equals(BuiltInAtomicType.STRING)) {
505
                            putIndex(doc, keySetNumber, t, "Under Construction", context);
506
                            index = buildIndex(keySet, t, null, doc, context);
507
                            putIndex(doc, keySetNumber, t, index, context);
508
                        }
506 509
                    }
507 510
                }
508 511
            }

Also available in: Unified diff