@@ -955,14 +955,13 @@ public IStoredNode updateChild(final Txn transaction, final Node oldChild, final
955
955
@ Override
956
956
@ EnsureContainerLocked (mode =READ_LOCK )
957
957
public Node getFirstChild () {
958
- if (children == 0 ) {
958
+ if (children == 0 ) {
959
959
return null ;
960
960
}
961
- try (final DBBroker broker = pool .getBroker ()) {
962
- return broker .objectWith (new NodeProxy ( getExpression (), this , NodeId . DOCUMENT_NODE , childAddress [ 0 ] ));
963
- } catch (final EXistException e ) {
961
+ try (final DBBroker broker = pool .getBroker ()) {
962
+ return broker .objectWith (getFirstChildProxy ( ));
963
+ } catch (final EXistException e ) {
964
964
LOG .warn ("Exception while inserting node: {}" , e .getMessage (), e );
965
- //TODO : throw exception ?
966
965
}
967
966
return null ;
968
967
}
@@ -995,14 +994,18 @@ public boolean hasChildNodes() {
995
994
@ EnsureContainerLocked (mode =READ_LOCK )
996
995
public NodeList getChildNodes () {
997
996
final org .exist .dom .NodeListImpl list = new org .exist .dom .NodeListImpl ();
997
+
998
+ @ Nullable final NodeProxy nodeProxy = children > 0 ? new NodeProxy (getExpression (), this , NodeId .DOCUMENT_NODE ) : null ;
998
999
try (final DBBroker broker = pool .getBroker ()) {
999
- for (int i = 0 ; i < children ; i ++) {
1000
- final Node child = broker .objectWith (new NodeProxy (getExpression (), this , NodeId .DOCUMENT_NODE , childAddress [i ]));
1000
+ for (int i = 0 ; i < children ; i ++) {
1001
+ nodeProxy .setInternalAddress (childAddress [i ]);
1002
+ final Node child = broker .objectWith (nodeProxy );
1001
1003
list .add (child );
1002
1004
}
1003
- } catch (final EXistException e ) {
1005
+ } catch (final EXistException e ) {
1004
1006
LOG .warn ("Exception while retrieving child nodes: {}" , e .getMessage (), e );
1005
1007
}
1008
+
1006
1009
return list ;
1007
1010
}
1008
1011
@@ -1308,7 +1311,7 @@ public Text createTextNode(final String data) {
1308
1311
@ Override
1309
1312
public Element getDocumentElement () {
1310
1313
try (final DBBroker broker = pool .getBroker ()) {
1311
- final NodeProxy childNodeProxy = new NodeProxy (getExpression (), this , NodeId .DOCUMENT_NODE );
1314
+ @ Nullable final NodeProxy childNodeProxy = children > 0 ? new NodeProxy (getExpression (), this , NodeId .DOCUMENT_NODE ) : null ;
1312
1315
for (int i = 0 ; i < children ; i ++) {
1313
1316
childNodeProxy .setInternalAddress (childAddress [i ]);
1314
1317
final Node child = broker .objectWith (childNodeProxy );
0 commit comments