@@ -1029,14 +1029,13 @@ public IStoredNode updateChild(final Txn transaction, final Node oldChild, final
1029
1029
@ Override
1030
1030
@ EnsureContainerLocked (mode =READ_LOCK )
1031
1031
public Node getFirstChild () {
1032
- if (children == 0 ) {
1032
+ if (children == 0 ) {
1033
1033
return null ;
1034
1034
}
1035
- try (final DBBroker broker = pool .getBroker ()) {
1036
- return broker .objectWith (new NodeProxy ( getExpression (), this , NodeId . DOCUMENT_NODE , childAddress [ 0 ] ));
1037
- } catch (final EXistException e ) {
1035
+ try (final DBBroker broker = pool .getBroker ()) {
1036
+ return broker .objectWith (getFirstChildProxy ( ));
1037
+ } catch (final EXistException e ) {
1038
1038
LOG .warn ("Exception while inserting node: {}" , e .getMessage (), e );
1039
- //TODO : throw exception ?
1040
1039
}
1041
1040
return null ;
1042
1041
}
@@ -1069,14 +1068,18 @@ public boolean hasChildNodes() {
1069
1068
@ EnsureContainerLocked (mode =READ_LOCK )
1070
1069
public NodeList getChildNodes () {
1071
1070
final org .exist .dom .NodeListImpl list = new org .exist .dom .NodeListImpl ();
1071
+
1072
+ @ Nullable final NodeProxy nodeProxy = children > 0 ? new NodeProxy (getExpression (), this , NodeId .DOCUMENT_NODE ) : null ;
1072
1073
try (final DBBroker broker = pool .getBroker ()) {
1073
- for (int i = 0 ; i < children ; i ++) {
1074
- final Node child = broker .objectWith (new NodeProxy (getExpression (), this , NodeId .DOCUMENT_NODE , childAddress [i ]));
1074
+ for (int i = 0 ; i < children ; i ++) {
1075
+ nodeProxy .setInternalAddress (childAddress [i ]);
1076
+ final Node child = broker .objectWith (nodeProxy );
1075
1077
list .add (child );
1076
1078
}
1077
- } catch (final EXistException e ) {
1079
+ } catch (final EXistException e ) {
1078
1080
LOG .warn ("Exception while retrieving child nodes: {}" , e .getMessage (), e );
1079
1081
}
1082
+
1080
1083
return list ;
1081
1084
}
1082
1085
@@ -1397,7 +1400,7 @@ public Text createTextNode(final String data) {
1397
1400
@ Override
1398
1401
public Element getDocumentElement () {
1399
1402
try (final DBBroker broker = pool .getBroker ()) {
1400
- final NodeProxy childNodeProxy = new NodeProxy (getExpression (), this , NodeId .DOCUMENT_NODE );
1403
+ @ Nullable final NodeProxy childNodeProxy = children > 0 ? new NodeProxy (getExpression (), this , NodeId .DOCUMENT_NODE ) : null ;
1401
1404
for (int i = 0 ; i < children ; i ++) {
1402
1405
childNodeProxy .setInternalAddress (childAddress [i ]);
1403
1406
final Node child = broker .objectWith (childNodeProxy );
0 commit comments