GithubHelp home page GithubHelp logo

Comments (2)

achenglike avatar achenglike commented on August 23, 2024

研究了2天吧,最终解决方法就是在 root工程的gradle.properties添加:

systemProp.javax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl

原因:

我觉得是 gradle 或者 agp 的bug,DocumentBuilderFactory#newInstance() 在找底层实现的时候,出现了同一个方法返回了两种实现一个是 com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl 另一个是 org.apache.xerces.jaxp.DocumentBuilderFactoryImpl 然后调用到 NodeUtils#adoptNode(Document document, Node node) 时 document和node来自不同的实现,adoptNode 就直接返回了NULL,后面就空指针了。

解决:

DocumentBuilderFactory#newInstance() 再向下走创建实例的过程中有一步是查看是否设置了SystemProperty

try {
            factoryClassName = SecuritySupport.getSystemProperty(factoryId);
            if (factoryClassName != null) {
                dPrint(() -> {
                    return "found system property, value=" + factoryClassName;
                });
                return newInstance(type, factoryClassName, (ClassLoader)null, true);
            }
        } catch (SecurityException var9) {
            if (debug) {
                var9.printStackTrace();
            }
        }

直接通过gradle.properties定义下这个property,这样获取的实现就一致了

求助:

DocumentBuilderFactory#newInstance() 后面的实例化 DocumentBuilderFactory 的过程中有使用ServiceLoader,

private static <T> T findServiceProvider(final Class<T> type) {
        try {
            return AccessController.doPrivileged(new PrivilegedAction<T>() {
                public T run() {
                    ServiceLoader<T> serviceLoader = ServiceLoader.load(type);
                    Iterator<T> iterator = serviceLoader.iterator();
                    return iterator.hasNext() ? iterator.next() : null;
                }
            });
        } catch (ServiceConfigurationError var4) {
            RuntimeException x = new RuntimeException("Provider for " + type + " cannot be created", var4);
            FactoryConfigurationError error = new FactoryConfigurationError(x, x.getMessage());
            throw error;
        }
    }

就是这个地方,出现了本插件使用流程中实例化查不到实现,其它情况能查到,哪位知道原因的话,烦请回复下。

from micromodule.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.