在MarkLogic 9中,是否需要在isAutoCommit上获取NPE,或在新会话对象上获取getUpdate?
在MarkLogic XCC版本9.0-3下,我在尝试调用新会话对象上的在MarkLogic 9中,是否需要在isAutoCommit上获取NPE,或在新会话对象上获取getUpdate?,marklogic,marklogic-9,Marklogic,Marklogic 9,在MarkLogic XCC版本9.0-3下,我在尝试调用新会话对象上的isAutoCommit或getUpdate时收到一个NullPointerException 如果先调用setAutoCommit或setUpdate,则不会发生NPE。这是故意的行为吗?若然,原因为何?即使未设置任何值,会话的所有其他getter也会返回而不出错 我构建了一个最小可行的示例: import java.net.URI; import com.marklogic.xcc.ContentSource; imp
isAutoCommit
或getUpdate
时收到一个NullPointerException
如果先调用setAutoCommit
或setUpdate
,则不会发生NPE。这是故意的行为吗?若然,原因为何?即使未设置任何值,会话的所有其他getter也会返回而不出错
我构建了一个最小可行的示例:
import java.net.URI;
import com.marklogic.xcc.ContentSource;
import com.marklogic.xcc.ContentSourceFactory;
import com.marklogic.xcc.Session;
public class mve {
public static void main(String[] args) throws Exception {
if (args.length != 1) {
System.err.println("usage: xcc://user:password@host:port/contentbase");
return;
}
System.out.println("Running minimal viable example of MarkLogic isAutoCommit/getUpdate bug...");
URI uri = new URI(args[0]);
ContentSource contentSource = ContentSourceFactory.newContentSource(uri);
Session updateSession = contentSource.newSession();
// comment out the following two lines to cause a NullPointerException to be thrown on getUpdate and isAutoCommit:
updateSession.setAutoCommit(false);
updateSession.setUpdate(Session.Update.TRUE);
System.out.println("is AutoCommit?");
System.out.println(updateSession.isAutoCommit()); // if lines 21 and 22 are both commented out, this will cause NPE
System.out.println("getUpdate?");
System.out.println(updateSession.getUpdate()); // if lines 21 and 22 are both commented out, this will cause NPE
}
}
这两个方法都尝试访问TransactionMode的属性,该属性为null 调用or或显式设置TransactionMode with将确保
txnMode
不是null
如果升级到9.0.4,SessionImplisAutoCommit()
将返回默认值true
,而不带NPE:
public boolean isAutoCommit() {
return txnMode == null ? true : txnMode.isAutoCommit();
}
但是,如果调用getUpdate()
而不建立txnMode
,仍然会得到NPE:
public Update getUpdate() {
return txnMode.getUpdate();
}
可能有理由期望它返回一个默认的
TransactionMode.AUTO
而不是NPE。我注意到对isAutoCommit
行为的更改不幸没有记录在文档中。