在 MarkLogic XCC 版本 9.0-3 下,尝试调用isAutoCommit
或getUpdate
在新的 Session 对象上时收到 NullPointerException。
如果先调用或,则不会发生NPE 。这是故意行为吗?如果是这样,为什么?即使没有设置任何值,Session 的所有其他 getter 也不会出错。setAutoCommit
setUpdate
我构建了一个最小的可行示例:
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
}
}