Search code examples
javamavennewrelicxerces

Updating NewRelic version throwing AbstractMethodError at runtime


I am updating the newrelic version from 2.x.x to 5.x.x in a project. I followed steps as mentioned in the newrelic docs (I updated the dependency version in pom file, updated the agent jar file and the config file).

But now on running project passing the required javaagent:

java -server -javaagent:/Users/amit.upadhyay/abcproject/abcproject-app/newrelic-stage/newrelic.jar -jar abcproject-app/target/abcproject-app-*.*.*-SNAPSHOT.jar /Users/amit.upadhyay/Downloads/abcproject.yml

I get java.lang.AbstractMethodError. Below is the error log:

ERROR StatusLogger Caught java.lang.AbstractMethodError setting feature http://xml.org/sax/features/external-general-entities to false on DocumentBuilderFactory org.apache.xerces.jaxp.DocumentBuilderFactoryImpl@e320068: java.lang.AbstractMethodError: javax.xml.parsers.DocumentBuilderFactory.setFeature(Ljava/lang/String;Z)V java.lang.AbstractMethodError: javax.xml.parsers.DocumentBuilderFactory.setFeature(Ljava/lang/String;Z)V   at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.xml.XmlConfiguration.setFeature(XmlConfiguration.java:212)  at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.xml.XmlConfiguration.disableDtdProcessing(XmlConfiguration.java:205)    at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.xml.XmlConfiguration.newDocumentBuilder(XmlConfiguration.java:194)  at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.xml.XmlConfiguration.<init>(XmlConfiguration.java:92)   at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.xml.XmlConfigurationFactory.getConfiguration(XmlConfigurationFactory.java:46)   at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:420)    at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:347)    at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:261)    at com.newrelic.agent.deps.org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:616)  at com.newrelic.agent.deps.org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:637)  at com.newrelic.agent.deps.org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:231)    at com.newrelic.agent.deps.org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:243)  at com.newrelic.agent.deps.org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)   at com.newrelic.agent.deps.org.apache.logging.log4j.LogManager.getContext(LogManager.java:174)  at com.newrelic.agent.deps.org.apache.logging.log4j.LogManager.getLogger(LogManager.java:648)   at com.newrelic.agent.logging.Log4jLogger.<init>(Log4jLogger.java:68)   at com.newrelic.agent.logging.Log4jLogger.create(Log4jLogger.java:415)  at com.newrelic.agent.logging.Log4jLogManager.createRootLogger(Log4jLogManager.java:38)     at com.newrelic.agent.logging.Log4jLogManager.initializeRootLogger(Log4jLogManager.java:98)     at com.newrelic.agent.logging.Log4jLogManager.<init>(Log4jLogManager.java:34)   at com.newrelic.agent.logging.Log4jLogManager.create(Log4jLogManager.java:254)  at com.newrelic.agent.logging.AgentLogManager.createAgentLogManager(AgentLogManager.java:19)    at com.newrelic.agent.logging.AgentLogManager.<clinit>(AgentLogManager.java:9)  at com.newrelic.agent.Agent.<clinit>(Agent.java:59)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)    at java.lang.reflect.Method.invoke(Method.java:498)     at com.newrelic.bootstrap.BootstrapAgent.startAgent(BootstrapAgent.java:179)    at com.newrelic.bootstrap.BootstrapAgent.premain(BootstrapAgent.java:81)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)    at java.lang.reflect.Method.invoke(Method.java:498)     at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:386)  at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:401) ERROR StatusLogger Caught java.lang.AbstractMethodError setting feature http://xml.org/sax/features/external-parameter-entities to false on DocumentBuilderFactory org.apache.xerces.jaxp.DocumentBuilderFactoryImpl@e320068: java.lang.AbstractMethodError: javax.xml.parsers.DocumentBuilderFactory.setFeature(Ljava/lang/String;Z)V java.lang.AbstractMethodError: javax.xml.parsers.DocumentBuilderFactory.setFeature(Ljava/lang/String;Z)V     at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.xml.XmlConfiguration.setFeature(XmlConfiguration.java:212)  at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.xml.XmlConfiguration.disableDtdProcessing(XmlConfiguration.java:206)    at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.xml.XmlConfiguration.newDocumentBuilder(XmlConfiguration.java:194)  at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.xml.XmlConfiguration.<init>(XmlConfiguration.java:92)   at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.xml.XmlConfigurationFactory.getConfiguration(XmlConfigurationFactory.java:46)   at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:420)    at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:347)    at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:261)    at com.newrelic.agent.deps.org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:616)  at com.newrelic.agent.deps.org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:637)  at com.newrelic.agent.deps.org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:231)    at com.newrelic.agent.deps.org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:243)  at com.newrelic.agent.deps.org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)   at com.newrelic.agent.deps.org.apache.logging.log4j.LogManager.getContext(LogManager.java:174)  at com.newrelic.agent.deps.org.apache.logging.log4j.LogManager.getLogger(LogManager.java:648)   at com.newrelic.agent.logging.Log4jLogger.<init>(Log4jLogger.java:68)   at com.newrelic.agent.logging.Log4jLogger.create(Log4jLogger.java:415)  at com.newrelic.agent.logging.Log4jLogManager.createRootLogger(Log4jLogManager.java:38)     at com.newrelic.agent.logging.Log4jLogManager.initializeRootLogger(Log4jLogManager.java:98)     at com.newrelic.agent.logging.Log4jLogManager.<init>(Log4jLogManager.java:34)   at com.newrelic.agent.logging.Log4jLogManager.create(Log4jLogManager.java:254)  at com.newrelic.agent.logging.AgentLogManager.createAgentLogManager(AgentLogManager.java:19)    at com.newrelic.agent.logging.AgentLogManager.<clinit>(AgentLogManager.java:9)  at com.newrelic.agent.Agent.<clinit>(Agent.java:59)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)    at java.lang.reflect.Method.invoke(Method.java:498)     at com.newrelic.bootstrap.BootstrapAgent.startAgent(BootstrapAgent.java:179)    at com.newrelic.bootstrap.BootstrapAgent.premain(BootstrapAgent.java:81)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)    at java.lang.reflect.Method.invoke(Method.java:498)     at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:386)  at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:401) ERROR StatusLogger Caught java.lang.AbstractMethodError setting feature http://apache.org/xml/features/nonvalidating/load-external-dtd to false on DocumentBuilderFactory org.apache.xerces.jaxp.DocumentBuilderFactoryImpl@e320068: java.lang.AbstractMethodError: javax.xml.parsers.DocumentBuilderFactory.setFeature(Ljava/lang/String;Z)V java.lang.AbstractMethodError: javax.xml.parsers.DocumentBuilderFactory.setFeature(Ljava/lang/String;Z)V  at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.xml.XmlConfiguration.setFeature(XmlConfiguration.java:212)  at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.xml.XmlConfiguration.disableDtdProcessing(XmlConfiguration.java:207)    at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.xml.XmlConfiguration.newDocumentBuilder(XmlConfiguration.java:194)  at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.xml.XmlConfiguration.<init>(XmlConfiguration.java:92)   at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.xml.XmlConfigurationFactory.getConfiguration(XmlConfigurationFactory.java:46)   at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:420)    at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:347)    at com.newrelic.agent.deps.org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:261)    at com.newrelic.agent.deps.org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:616)  at com.newrelic.agent.deps.org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:637)  at com.newrelic.agent.deps.org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:231)    at com.newrelic.agent.deps.org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:243)  at com.newrelic.agent.deps.org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)   at com.newrelic.agent.deps.org.apache.logging.log4j.LogManager.getContext(LogManager.java:174)  at com.newrelic.agent.deps.org.apache.logging.log4j.LogManager.getLogger(LogManager.java:648)   at com.newrelic.agent.logging.Log4jLogger.<init>(Log4jLogger.java:68)   at com.newrelic.agent.logging.Log4jLogger.create(Log4jLogger.java:415)  at com.newrelic.agent.logging.Log4jLogManager.createRootLogger(Log4jLogManager.java:38)     at com.newrelic.agent.logging.Log4jLogManager.initializeRootLogger(Log4jLogManager.java:98)     at com.newrelic.agent.logging.Log4jLogManager.<init>(Log4jLogManager.java:34)   at com.newrelic.agent.logging.Log4jLogManager.create(Log4jLogManager.java:254)  at com.newrelic.agent.logging.AgentLogManager.createAgentLogManager(AgentLogManager.java:19)    at com.newrelic.agent.logging.AgentLogManager.<clinit>(AgentLogManager.java:9)  at com.newrelic.agent.Agent.<clinit>(Agent.java:59)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)    at java.lang.reflect.Method.invoke(Method.java:498)     at com.newrelic.bootstrap.BootstrapAgent.startAgent(BootstrapAgent.java:179)    at com.newrelic.bootstrap.BootstrapAgent.premain(BootstrapAgent.java:81)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)    at java.lang.reflect.Method.invoke(Method.java:498)     at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:386)  at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:401) Mar 16, 2020 01:40:38 +0530 [8698 1] com.newrelic INFO: Configuration file not found. The agent will attempt to read required values from environment variables. Mar 16, 2020 01:40:38 +0530 [8698 1] com.newrelic INFO: Using default collector host: collector.newrelic.com Mar 16, 2020 01:40:38 +0530 [8698 1] com.newrelic ERROR: Unable to start the New Relic Agent. Your application will continue to run but it will not be monitored. com.newrelic.agent.config.ConfigurationException: The agent requires an application name. Check the app_name setting in newrelic.yml    at com.newrelic.agent.config.ConfigServiceFactory.validateConfig(ConfigServiceFactory.java:64)  at com.newrelic.agent.config.ConfigServiceFactory.createConfigService(ConfigServiceFactory.java:27)

Since I am encountering AbstractMethodError at runtime i.e. somewhere I am using an old interface that is updated in the new versions of newrelic java agent 5.x.x.

The error logs suggested that there is a conflict between xerces version being used in my project and what is there in the updated newrelic javaagent. On googling I found these two SO links first and second with similar kinda issue. According to answers given, I added

        <dependency>
            <groupId>xerces</groupId>
            <artifactId>xercesImpl</artifactId>
            <version>2.11.0</version>
        </dependency>

        <dependency>
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis</artifactId>
            <version>1.4.01</version>
        </dependency>

to my pom file and this AbstractMethodError error was gone.

But then on running again I started getting this exception: com.newrelic.agent.config.ConfigurationException

The logs for this exception is:

Mar 16, 2020 02:37:18 +0530 [9598 1] com.newrelic INFO: Configuration file not found. The agent will attempt to read required values from environment variables.
Mar 16, 2020 02:37:18 +0530 [9598 1] com.newrelic INFO: Using default collector host: collector.newrelic.com
Mar 16, 2020 02:37:18 +0530 [9598 1] com.newrelic ERROR: Unable to start the New Relic Agent. Your application will continue to run but it will not be monitored.
com.newrelic.agent.config.ConfigurationException: The agent requires an application name. Check the app_name setting in newrelic.yml
    at com.newrelic.agent.config.ConfigServiceFactory.validateConfig(ConfigServiceFactory.java:64) ~
    at com.newrelic.agent.config.ConfigServiceFactory.createConfigService(ConfigServiceFactory.java:27) ~
    at com.newrelic.agent.service.ServiceManagerImpl.<init>(ServiceManagerImpl.java:126) ~
    at com.newrelic.agent.Agent.premain(Agent.java:279) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_222]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_222]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_222]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_222]
    at com.newrelic.bootstrap.BootstrapAgent.startAgent(BootstrapAgent.java:179) 
    at com.newrelic.bootstrap.BootstrapAgent.premain(BootstrapAgent.java:81) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_222]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_222]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_222]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_222]
    at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:386) [?:1.8.0_222]
    at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:401) [?:1.8.0_222]

Now, I don't understand why is this throwing ConfigurationException (or why is it not able to find the configuration file). The same java command (with exactly the same path of agent jar and configuration file) when used with an older version of newrelic agent(2.x.x or 3.x.x) runs perfectly.

I wanted to understand what is going wrong/missing here?


Solution

  • I was able to update to the latest newrelic version in my project. It seems that they have updated the xerces version in their java agent where version is greater than 5.0.0. Along with the fix of updating xerces version, I needed to pass the newrelic config file explicitly as system properties to resolve the ConfigurationException.

    Overall summary: - update these libraries to

            <dependency>
                <groupId>xerces</groupId>
                <artifactId>xercesImpl</artifactId>
                <version>2.11.0</version>
            </dependency>
    
            <dependency>
                <groupId>xml-apis</groupId>
                <artifactId>xml-apis</artifactId>
                <version>1.4.01</version>
            </dependency>
    

    And pass the newrelic config file as system property:

    -Dnewrelic.config.file=./${NEW_RELIC_DIR_NAME}/newrelic.yml