ClassCastException when starting Java agent in BaseConfig.java:244

Hi,
I am experiencing a java.lang.ClassCastException when starting the agent:

2022-01-10T10:22:34,674+0000 [2546 1] com.newrelic INFO: New Relic Agent: Loading configuration file "newrelic.yml"
2022-01-10T10:22:34,770+0000 [2546 1] com.newrelic INFO: Using default collector host: collector.newrelic.com
2022-01-10T10:22:34,771+0000 [2546 1] com.newrelic INFO: Using default metric ingest URI: https://metric-api.newrelic.com/metric/v1
2022-01-10T10:22:34,771+0000 [2546 1] com.newrelic INFO: Using default event ingest URI: https://insights-collector.newrelic.com/v1/accounts/events
2022-01-10T10:22:34,772+0000 [2546 1] com.newrelic ERROR: Unable to start the New Relic Agent. Your application will continue to run but it will not be monitored.
java.lang.ClassCastException: class java.lang.String cannot be cast to class java.lang.Number (java.lang.String and java.lang.Number are in module java.base of loader 'bootstrap')
        at com.newrelic.agent.config.BaseConfig.getIntProperty(BaseConfig.java:244) ~[newrelic.jar:7.4.3]
        at com.newrelic.agent.config.AgentConfigImpl.<init>(AgentConfigImpl.java:304) ~[newrelic.jar:7.4.3]
        at com.newrelic.agent.config.AgentConfigImpl.createAgentConfig(AgentConfigImpl.java:277) ~[newrelic.jar:7.4.3]
        at com.newrelic.agent.config.ConfigServiceFactory.createConfigService(ConfigServiceFactory.java:38) ~[newrelic.jar:7.4.3]
        at com.newrelic.agent.Agent.tryToInitializeServiceManager(Agent.java:211) [newrelic.jar:7.4.3]
        at com.newrelic.agent.Agent.continuePremain(Agent.java:152) [newrelic.jar:7.4.3]
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
        at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
        at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
        at com.newrelic.bootstrap.BootstrapAgent.startAgent(BootstrapAgent.java:176) [newrelic.jar:7.4.3]
        at com.newrelic.bootstrap.BootstrapAgent.premain(BootstrapAgent.java:113) [newrelic.jar:7.4.3]
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
        at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
        at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
        at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:513) [?:?]
        at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:525) [?:?]

Unfortunately, I am not able to find out which config is initialized here BaseConfig.java:244

Version: 7.4.3

Best regards,
Moritz

Hi, @moritz.behr1: It looks like one of the configuration settings in your newrelic.yml file contains a string when it should be a number. You might try commenting them out one by one until your application starts successfully, or compare your config file with the template in the documentation: Java agent config file template | New Relic Documentation.

You may also post the contents of your config file here (with the license key removed) and we can take a look at it.

Hi @philweber
Thanks for your reply.
I think it could be related to the proxy port we are using in staging/production.
But was hoping to find out by digging into the java code in BaseConfig.java:244 :smiley:

#
# This file configures the New Relic Agent.  New Relic monitors Ruby, Java,
# .NET, PHP, Python and Node applications with deep visibility and low
# overhead.  For more information, visit www.newrelic.com.
#
common: &default_settings
  # Required license key associated with your New Relic account.
  license_key: <%= ENV.fetch("NEW_RELIC_LICENSE_KEY").to_s %>

  # Your application name. Renaming here affects where data displays in New
  # Relic.  For more details, see https://docs.newrelic.com/docs/apm/new-relic-apm/maintenance/renaming-applications
  app_name: <%= ENV.fetch("NEW_RELIC_APP_NAME").to_s %>

  # To enable high security, set this property to true. When in high
  # security mode, the agent will use SSL and obfuscated SQL. Additionally,
  # request parameters and message parameters will not be sent to New Relic.
  high_security: true

  # To disable the agent regardless of other settings, uncomment the following:
  # agent_enabled: false

  # Logging level for log/newrelic_agent.log
  log_level: info
  ssl: true

# Environment-specific settings are in this section.
# RAILS_ENV or RACK_ENV (as appropriate) is used to determine the environment.
# If your application has other named environments, configure them here.
development:
  <<: *default_settings
  monitor_mode: false

test:
  <<: *default_settings
  monitor_mode: false

staging:
  <<: *default_settings
  proxy_host: <%= ENV.fetch("PROXY_HOST").to_s %>
  proxy_port: <%= ENV.fetch("PROXY_PORT").to_i %>
  log_file_path: "/var/tick/tack/tock"
  monitor_mode: <%= ENV.fetch("NEW_RELIC_MONITOR_MODE", true).to_s %>

production:
  <<: *default_settings
  proxy_host: <%= ENV.fetch("PROXY_HOST").to_s %>
  proxy_port: <%= ENV.fetch("PROXY_PORT").to_i %>
  log_file_path: "/var/tick/tack/tock"
  monitor_mode: <%= ENV.fetch("NEW_RELIC_MONITOR_MODE", true).to_s %>

You may view the agent source code here: https://github.com/newrelic/newrelic-java-agent.