@@ -955,14 +955,13 @@ public IStoredNode updateChild(final Txn transaction, final Node oldChild, final
955955 @ Override
956956 @ EnsureContainerLocked (mode =READ_LOCK )
957957 public Node getFirstChild () {
958- if (children == 0 ) {
958+ if (children == 0 ) {
959959 return null ;
960960 }
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 ) {
964964 LOG .warn ("Exception while inserting node: {}" , e .getMessage (), e );
965- //TODO : throw exception ?
966965 }
967966 return null ;
968967 }
@@ -995,14 +994,18 @@ public boolean hasChildNodes() {
995994 @ EnsureContainerLocked (mode =READ_LOCK )
996995 public NodeList getChildNodes () {
997996 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 ;
998999 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 );
10011003 list .add (child );
10021004 }
1003- } catch (final EXistException e ) {
1005+ } catch (final EXistException e ) {
10041006 LOG .warn ("Exception while retrieving child nodes: {}" , e .getMessage (), e );
10051007 }
1008+
10061009 return list ;
10071010 }
10081011
@@ -1308,7 +1311,7 @@ public Text createTextNode(final String data) {
13081311 @ Override
13091312 public Element getDocumentElement () {
13101313 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 ;
13121315 for (int i = 0 ; i < children ; i ++) {
13131316 childNodeProxy .setInternalAddress (childAddress [i ]);
13141317 final Node child = broker .objectWith (childNodeProxy );
0 commit comments