我们的生产系统(Java7运行时)中的XSLT转换偶尔会失败,并且会出现下面提供的NullPointerException。 据我所知,在Saxon9源代码中,LRUCache类是AnyURIValue类中的静态类成员。 我对此做了一些研究,并读到这可能是由于并发和非同步调用 底层LinkedHashMap,它可以解释问题似乎在我们随机的时间点出现。
The [java.lang.NullPointerException] occurred during XSLT transformation: java.lang.NullPointerException
at com.tibco.plugin.xml.XMLTransformActivity.eval(Unknown Source)
at com.tibco.pe.plugin.Activity.eval(Unknown Source)
at com.tibco.pe.core.TaskImpl.eval(Unknown Source)
at com.tibco.pe.core.Job.a(Unknown Source)
at com.tibco.pe.core.Job.k(Unknown Source)
at com.tibco.pe.core.JobDispatcher$JobCourier.a(Unknown Source)
at com.tibco.pe.core.JobDispatcher$JobCourier.run(Unknown Source)
caused by: java.lang.NullPointerException at java.util.LinkedHashMap$Entry.remove(Unknown Source)
at java.util.LinkedHashMap$Entry.recordRemoval(Unknown Source)
at java.util.HashMap.removeEntryForKey(Unknown Source)
at java.util.LinkedHashMap.addEntry(Unknown Source)
at java.util.HashMap.put(Unknown Source)
at net.sf.saxon.sort.LRUCache.put(LRUCache.java:47)
at net.sf.saxon.value.AnyURIValue.isValidURI(AnyURIValue.java:103)
at net.sf.saxon.instruct.Namespace.checkPrefixAndUri(Namespace.java:184)
at net.sf.saxon.instruct.Namespace.processLeavingTail(Namespace.java:144)
at net.sf.saxon.instruct.Block.processLeavingTail(Block.java:399)
at net.sf.saxon.instruct.Instruction.process(Instruction.java:94)
at net.sf.saxon.instruct.ElementCreator.processLeavingTail(ElementCreator.java:298)
at net.sf.saxon.instruct.Template.applyLeavingTail(Template.java:175)
at net.sf.saxon.instruct.ApplyTemplates.applyTemplates(ApplyTemplates.java:343)
at net.sf.saxon.instruct.ApplyTemplates.defaultAction(ApplyTemplates.java:376)
at net.sf.saxon.instruct.ApplyTemplates.applyTemplates(ApplyTemplates.java:331)
at net.sf.saxon.Controller.transformDocument(Controller.java:1735)
at net.sf.saxon.Controller.transform(Controller.java:1559)
at com.tibco.plugin.xml.XMLTransformActivity.new(Unknown Source)
at com.tibco.plugin.xml.XMLTransformActivity.eval(Unknown Source)
at com.tibco.pe.plugin.Activity.eval(Unknown Source)
at com.tibco.pe.core.TaskImpl.eval(Unknown Source)
at com.tibco.pe.core.Job.a(Unknown Source)
at com.tibco.pe.core.Job.k(Unknown Source)
at com.tibco.pe.core.JobDispatcher$JobCourier.a(Unknown Source)
at com.tibco.pe.core.JobDispatcher$JobCourier.run(Unknown Source)
答案 0 :(得分:1)
Saxon9不是一个版本,而是6个主要版本(9.0到9.5)的序列,以及在大约7年的时间内发布的更多维护版本。您需要更准确地了解您正在使用的版本。
多年来,针对LRUCache的问题已经有了一些修复,例如
https://saxonica.plan.io/issues/1481 https://saxonica.plan.io/issues/1619
虽然这些都没有将NullPointerException描述为观察到的症状,但它们可能反映出相同的根本原因。
Saxon 9.5代码在需要的情况下使用ConcurrentHashMap,而AnyURIValue类不再使用LRUCache。
答案 1 :(得分:0)
转载行为,它似乎是Saxon9的命名空间LRUCache中的并发问题。错误 发生了put以及缓存上的get操作。下面的代码模拟了问题。 LRUCache是Saxon的AnyURIValue.class中的静态类成员,以及对底层的访问 LinkedHashMap未同步。
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
public class Main {
private static final int NTHREDS = 100;
private static final int EXECUTION_COUNT = 10000;
public static void main(String[] args) throws InterruptedException {
ExecutorService executor = Executors.newFixedThreadPool(NTHREDS);
for (int i = 0; i < EXECUTION_COUNT; i++) {
Runnable worker = new TestRunnable(i);
executor.execute(worker);
}
executor.shutdown();
executor.awaitTermination(10, TimeUnit.SECONDS);
}
}
import net.sf.saxon.sort.LRUCache;
public class TestRunnable implements Runnable {
private static LRUCache cache = new LRUCache(20); // The LRUCache is a static member in Saxon's AnyURIValue.class!
private int number;
public TestRunnable(int number){
this.number = number;
}
@Override
public void run() {
/**
* Access elements in ascending order to trigger the call to LinkedHashMap$Entry.remove;
*/
for(int i = 0; i < number; i++){
cache.get(new Integer(i));
}
/**
* Add the new element to the cache.
* As soon as the cacheSize exceeds 20, the cache is starting to remove the last accessed element.
*/
cache.put(new Integer(number), new Integer(number));
}
}