Skip to content

Commit c553667

Browse files
[feature] Change XPathException construct calls so that they do not pass null expressions, and re-add expressionless constructors (so as not to break existing code that expects expressionless constructors)
1 parent d3dde0d commit c553667

File tree

243 files changed

+1994
-705
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

243 files changed

+1994
-705
lines changed

exist-core/src/main/antlr/org/exist/xquery/parser/DeclScanner.g

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
header {
2323
package org.exist.xquery.parser;
2424

25-
import org.exist.xquery.Expression;
2625
import org.exist.xquery.XPathException;
2726
}
2827

exist-core/src/main/java/org/exist/Indexer.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.exist.util.XMLString;
5050
import org.exist.util.pool.NodePool;
5151
import org.exist.xquery.Constants;
52+
import org.exist.xquery.Expression;
5253
import org.exist.xquery.value.StringValue;
5354
import org.w3c.dom.DOMException;
5455
import org.w3c.dom.Element;
@@ -136,7 +137,7 @@ private enum ProcessTextParent { COMMENT, PI, CDATA_START, ELEMENT_START, ELEMEN
136137
private int nodeFactoryInstanceCnt = 0;
137138

138139
// reusable fields
139-
private final TextImpl text = new TextImpl();
140+
private final TextImpl text = new TextImpl((Expression) null);
140141
private final Deque<ElementImpl> usedElements = new ArrayDeque<>();
141142

142143
// when storing the document data, validation will be switched off, so
@@ -255,7 +256,7 @@ public void comment(final char[] ch, final int start, final int length) {
255256
if (insideDTD) {
256257
return;
257258
}
258-
final CommentImpl comment = new CommentImpl(ch, start, length);
259+
final CommentImpl comment = new CommentImpl(null, ch, start, length);
259260
comment.setOwnerDocument(document);
260261
if (stack.isEmpty()) {
261262
comment.setNodeId(broker.getBrokerPool().getNodeFactory()
@@ -280,7 +281,7 @@ public void endCDATA() {
280281
if (!stack.isEmpty()) {
281282
final ElementImpl last = stack.peek();
282283
if (charBuf != null && charBuf.length() > 0) {
283-
final CDATASectionImpl cdata = new CDATASectionImpl(charBuf);
284+
final CDATASectionImpl cdata = new CDATASectionImpl((last != null) ? last.getExpression() : null, charBuf);
284285
cdata.setOwnerDocument(document);
285286
last.appendChildInternal(prevNode, cdata);
286287
if (!validate) {
@@ -479,7 +480,7 @@ public void ignorableWhitespace(final char[] ch, final int start, final int leng
479480

480481
@Override
481482
public void processingInstruction(final String target, final String data) {
482-
final ProcessingInstructionImpl pi = new ProcessingInstructionImpl(target, data);
483+
final ProcessingInstructionImpl pi = new ProcessingInstructionImpl((Expression) null, target, data);
483484
pi.setOwnerDocument(document);
484485
if (stack.isEmpty()) {
485486
pi.setNodeId(broker.getBrokerPool().getNodeFactory().createInstance(nodeFactoryInstanceCnt++));
@@ -515,7 +516,7 @@ public void startCDATA() {
515516

516517
@Override
517518
public void startDTD(final String name, final String publicId, final String systemId) {
518-
final DocumentTypeImpl docType = new DocumentTypeImpl(name, publicId, systemId);
519+
final DocumentTypeImpl docType = new DocumentTypeImpl(null, name, publicId, systemId);
519520
document.setDocumentType(docType);
520521
insideDTD = true;
521522
}
@@ -577,7 +578,7 @@ public void startElement(final String namespace, final String name, final String
577578
node = usedElements.pop();
578579
node.setNodeName(qn, broker.getBrokerPool().getSymbols());
579580
} else {
580-
node = new ElementImpl(qn, broker.getBrokerPool().getSymbols());
581+
node = new ElementImpl((last != null) ? last.getExpression() : null, qn, broker.getBrokerPool().getSymbols());
581582
}
582583
} catch (final DOMException e) {
583584
throw new SAXException(e.getMessage(), e);
@@ -605,7 +606,7 @@ public void startElement(final String namespace, final String name, final String
605606
}
606607
} else {
607608
try {
608-
node = new ElementImpl(qn, broker.getBrokerPool().getSymbols());
609+
node = new ElementImpl(null, qn, broker.getBrokerPool().getSymbols());
609610
} catch (final DOMException e) {
610611
throw new SAXException(e.getMessage(), e);
611612
}

exist-core/src/main/java/org/exist/backup/restore/AbstractRestoreHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ private DeferredPermission restoreResourceEntry(final Attributes attributes) thr
369369

370370
final DocumentType docType;
371371
if (publicId != null || systemId != null) {
372-
docType = new DocumentTypeImpl(nameDocType, publicId, systemId);
372+
docType = new DocumentTypeImpl(null, nameDocType, publicId, systemId);
373373
} else {
374374
docType = null;
375375
}

exist-core/src/main/java/org/exist/backup/xquery/ListBackups.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public ListBackups(final XQueryContext context )
6363
public Sequence eval(final Sequence[] args, final Sequence contextSequence ) throws XPathException
6464
{
6565
if(!context.getEffectiveUser().hasDbaRole()) {
66-
throw new XPathException("You must be a DBA to list available backups");
66+
throw new XPathException(this, "You must be a DBA to list available backups");
6767
}
6868

6969
final String exportDir = args[0].getStringValue();

exist-core/src/main/java/org/exist/backup/xquery/RetrieveBackup.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public RetrieveBackup(final XQueryContext context )
5656
public Sequence eval(final Sequence[] args, final Sequence contextSequence ) throws XPathException
5757
{
5858
if(!context.getEffectiveUser().hasDbaRole()) {
59-
throw new XPathException("You must be a DBA to retrieve a backup");
59+
throw new XPathException(this, "You must be a DBA to retrieve a backup");
6060
}
6161

6262
final String exportDir = args[0].getStringValue();
@@ -73,7 +73,7 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence ) thr
7373
}
7474

7575
if( !name.endsWith( ".zip" ) ) {
76-
throw( new XPathException( this, "for security reasons, the function only allows " + "reading zipped backup archives" ) );
76+
throw( new XPathException(this, "for security reasons, the function only allows " + "reading zipped backup archives" ) );
7777
}
7878

7979
try {

exist-core/src/main/java/org/exist/collections/CollectionConfigurationManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.exist.util.XMLReaderPool;
4242
import org.exist.util.sanity.SanityCheck;
4343
import org.exist.xmldb.XmldbURI;
44+
import org.exist.xquery.Expression;
4445
import org.w3c.dom.Document;
4546
import org.xml.sax.InputSource;
4647
import org.xml.sax.XMLReader;
@@ -152,7 +153,7 @@ public void addConfiguration(final Txn txn, final DBBroker broker, final Collect
152153
*/
153154
public void testConfiguration(DBBroker broker, String config) throws CollectionConfigurationException {
154155
try {
155-
final SAXAdapter adapter = new SAXAdapter();
156+
final SAXAdapter adapter = new SAXAdapter((Expression) null);
156157
final InputSource src = new InputSource(new StringReader(config));
157158
final XMLReaderPool parserPool = broker.getBrokerPool().getParserPool();
158159
XMLReader reader = null;

exist-core/src/main/java/org/exist/collections/MutableCollection.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,7 +1543,7 @@ private IndexInfo validateXMLResourceInternal(final Txn transaction, final DBBro
15431543

15441544
// NOTE: the new `document` object actually gets discarded in favour of the `oldDoc` below if there is an oldDoc and it is XML (so we can use -1 as the docId because it will never be used)
15451545
final int docId = (oldDoc != null && oldDoc.getResourceType() == DocumentImpl.XML_FILE) ? - 1 : broker.getNextResourceId(transaction);
1546-
DocumentImpl document = new DocumentImpl((BrokerPool) db, this, docId, name);
1546+
DocumentImpl document = new DocumentImpl(null, (BrokerPool) db, this, docId, name);
15471547

15481548
checkCollectionConflict(name);
15491549
manageDocumentInformation(oldDoc, document);
@@ -1772,9 +1772,9 @@ public BinaryDocument addBinaryResource(final Txn transaction, final DBBroker br
17721772
final int docId = broker.getNextResourceId(transaction);
17731773
final BinaryDocument blob;
17741774
if (oldDoc != null) {
1775-
blob = new BinaryDocument(docId, oldDoc);
1775+
blob = new BinaryDocument(null, docId, oldDoc);
17761776
} else {
1777-
blob = new BinaryDocument(broker.getBrokerPool(), this, docId, name);
1777+
blob = new BinaryDocument(null, broker.getBrokerPool(), this, docId, name);
17781778
}
17791779

17801780
return addBinaryResource(db, transaction, broker, blob, is, mimeType, size, created, modified, permission,
@@ -1787,7 +1787,7 @@ public BinaryDocument addBinaryResource(final Txn transaction, final DBBroker br
17871787
public BinaryDocument validateBinaryResource(final Txn transaction, final DBBroker broker, final XmldbURI name) throws PermissionDeniedException, LockException, TriggerException, IOException {
17881788
try {
17891789
final int docId = broker.getNextResourceId(transaction);
1790-
return new BinaryDocument(broker.getBrokerPool(), this, docId, name);
1790+
return new BinaryDocument(null, broker.getBrokerPool(), this, docId, name);
17911791
} catch (final EXistException e) {
17921792
throw new IOException(e.getMessage(), e);
17931793
}

exist-core/src/main/java/org/exist/config/Configurator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
import org.exist.util.serializer.SAXSerializer;
7676
import org.exist.xmldb.FullXmldbURI;
7777
import org.exist.xmldb.XmldbURI;
78+
import org.exist.xquery.Expression;
7879
import org.w3c.dom.Element;
7980
import org.xml.sax.InputSource;
8081
import org.xml.sax.SAXException;
@@ -755,7 +756,7 @@ public static Configuration parse(final InputStream is) throws ConfigurationExce
755756
reader.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
756757
reader.setFeature(FEATURE_SECURE_PROCESSING, true);
757758

758-
final SAXAdapter adapter = new SAXAdapter();
759+
final SAXAdapter adapter = new SAXAdapter((Expression) null);
759760
reader.setContentHandler(adapter);
760761
reader.setProperty(Namespaces.SAX_LEXICAL_HANDLER, adapter);
761762
reader.parse(src);

exist-core/src/main/java/org/exist/dom/INode.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
*/
2222
package org.exist.dom;
2323

24+
import org.exist.xquery.Expression;
25+
2426
/**
2527
* Interface for Nodes in eXist
2628
* used for both persistent and
@@ -48,4 +50,11 @@ public interface INode<D extends org.w3c.dom.Document, T extends INode> extends
4850

4951
//TODO try and get rid of this after decoupling nameTyping from QName class (AR)?
5052
void setQName(QName qname);
53+
54+
/**
55+
* Get the expression from which this node derives.
56+
*
57+
* @return The expression from which this node derives
58+
*/
59+
Expression getExpression();
5160
}

exist-core/src/main/java/org/exist/dom/memtree/AbstractCharacterData.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222
package org.exist.dom.memtree;
2323

24+
import org.exist.xquery.Expression;
2425
import org.exist.xquery.NodeTest;
2526
import org.exist.xquery.XPathException;
2627
import org.exist.xquery.value.Sequence;
@@ -32,7 +33,11 @@
3233
public abstract class AbstractCharacterData extends NodeImpl implements CharacterData {
3334

3435
public AbstractCharacterData(final DocumentImpl doc, final int nodeNumber) {
35-
super(doc, nodeNumber);
36+
this(null, doc, nodeNumber);
37+
}
38+
39+
public AbstractCharacterData(final Expression expression, final DocumentImpl doc, final int nodeNumber) {
40+
super(expression, doc, nodeNumber);
3641
}
3742

3843
@Override

0 commit comments

Comments
 (0)