java.lang.NullPointerException

Spring JIRA | Victor Kolosov | 1 decade ago
  1. 0

    I had a messageSource configured like this: <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> <property name="basenames"> <list> <value>/WEB-INF/classes/validation</value> </list> </property> <property name="parentMessageSource"> <bean id="baseMessageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basenames"> <list> <value>messages</value> <value>filters</value> </list> </property> <property name="useCodeAsDefaultMessage"> <value>true</value> </property> </bean> </property> <property name="cacheSeconds"> <value>300</value> </property> </bean> this was in my context as well but without any additional AOP: <bean id="aapc" class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"> <property name="proxyTargetClass" value="true"/> </bean> and it all worked fine untill I put in this Advisor: <bean id="exceptionAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor"> <property name="pointcut"> <bean class="org.springframework.aop.TruePointcut"/> </property> <property name="advice"> <bean id="exceptionAdvice" class="com.poindexter.ssm.aop.EmailNotificationThrowsAdvice"> <property name="mailSender" ref="mailSender"/> <property name="defaultMailMessage"> <bean id="bugMessage" class="org.springframework.mail.SimpleMailMessage"> <property name="from" value="${bugMail.sendTo}"/> <property name="to" value="${bugMail.sendTo}"/> <property name="subject" value="${bugMail.subject}"/> </bean> </property> </bean> </property> </bean> here is my Advice: public class EmailNotificationThrowsAdvice implements ThrowsAdvice { private final Log logger = LogFactory.getLog(getClass()); protected JavaMailSender mailSender; protected SimpleMailMessage defaultMailMessage; public void setMailSender(JavaMailSender mailSender) { this.mailSender = mailSender; } public void setDefaultMailMessage(SimpleMailMessage defaultMailMessage) { this.defaultMailMessage = defaultMailMessage; } public void afterThrowing(Method m,Object[] args,Object target, Exception ex){ SimpleMailMessage msg = new SimpleMailMessage(defaultMailMessage); "+ex.getMessage()); msg.setText("Method: '"+m+"'\n Has thrown an exception with message: "+ex.getMessage()); try { mailSender.send(msg); } catch (Exception e) { logger.error("Sending bug mail has failed: "+e.getMessage()); } } } I have a calss ACTest that extends TestCase with this method: public void testRB() { MessageSource ms = (MessageSource) ac.getBean("messageSource"); System.out.println("ms.getMessage: "+ms.getMessage("filter.displayname.status", null, null)); } Now when I just run it I get this error [junit] Testcase: testRB(com.mycompany.ACTest): Caused an ERROR [junit] null [junit] java.lang.NullPointerException [junit] at org.springframework.context.support.ReloadableResourceBundleMessageSource.getMergedProperties(ReloadableResourceBundleMessageSource.java:295) [junit] at org.springframework.context.support.ReloadableResourceBundleMessageSource.resolveCodeWithoutArguments(ReloadableResourceBundleMessageSource.java:233) [junit] at org.springframework.context.support.AbstractMessageSource.getMessageInternal(AbstractMessageSource.java:207) [junit] at org.springframework.context.support.AbstractMessageSource.getMessage(AbstractMessageSource.java:147) [junit] at com.poindexter.ACTest.testRB(ACTest.java:36) [junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [junit] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) It appears to be failing on 'ReloadableResourceBundleMessageSource.resolveCodeWithoutArguments' but as soon as I remove my advice declaration it works again. It should be easily replicatable on your end.

    Spring JIRA | 1 decade ago | Victor Kolosov
    java.lang.NullPointerException
  2. 0

    I had a messageSource configured like this: <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> <property name="basenames"> <list> <value>/WEB-INF/classes/validation</value> </list> </property> <property name="parentMessageSource"> <bean id="baseMessageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basenames"> <list> <value>messages</value> <value>filters</value> </list> </property> <property name="useCodeAsDefaultMessage"> <value>true</value> </property> </bean> </property> <property name="cacheSeconds"> <value>300</value> </property> </bean> this was in my context as well but without any additional AOP: <bean id="aapc" class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"> <property name="proxyTargetClass" value="true"/> </bean> and it all worked fine untill I put in this Advisor: <bean id="exceptionAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor"> <property name="pointcut"> <bean class="org.springframework.aop.TruePointcut"/> </property> <property name="advice"> <bean id="exceptionAdvice" class="com.poindexter.ssm.aop.EmailNotificationThrowsAdvice"> <property name="mailSender" ref="mailSender"/> <property name="defaultMailMessage"> <bean id="bugMessage" class="org.springframework.mail.SimpleMailMessage"> <property name="from" value="${bugMail.sendTo}"/> <property name="to" value="${bugMail.sendTo}"/> <property name="subject" value="${bugMail.subject}"/> </bean> </property> </bean> </property> </bean> here is my Advice: public class EmailNotificationThrowsAdvice implements ThrowsAdvice { private final Log logger = LogFactory.getLog(getClass()); protected JavaMailSender mailSender; protected SimpleMailMessage defaultMailMessage; public void setMailSender(JavaMailSender mailSender) { this.mailSender = mailSender; } public void setDefaultMailMessage(SimpleMailMessage defaultMailMessage) { this.defaultMailMessage = defaultMailMessage; } public void afterThrowing(Method m,Object[] args,Object target, Exception ex){ SimpleMailMessage msg = new SimpleMailMessage(defaultMailMessage); "+ex.getMessage()); msg.setText("Method: '"+m+"'\n Has thrown an exception with message: "+ex.getMessage()); try { mailSender.send(msg); } catch (Exception e) { logger.error("Sending bug mail has failed: "+e.getMessage()); } } } I have a calss ACTest that extends TestCase with this method: public void testRB() { MessageSource ms = (MessageSource) ac.getBean("messageSource"); System.out.println("ms.getMessage: "+ms.getMessage("filter.displayname.status", null, null)); } Now when I just run it I get this error [junit] Testcase: testRB(com.mycompany.ACTest): Caused an ERROR [junit] null [junit] java.lang.NullPointerException [junit] at org.springframework.context.support.ReloadableResourceBundleMessageSource.getMergedProperties(ReloadableResourceBundleMessageSource.java:295) [junit] at org.springframework.context.support.ReloadableResourceBundleMessageSource.resolveCodeWithoutArguments(ReloadableResourceBundleMessageSource.java:233) [junit] at org.springframework.context.support.AbstractMessageSource.getMessageInternal(AbstractMessageSource.java:207) [junit] at org.springframework.context.support.AbstractMessageSource.getMessage(AbstractMessageSource.java:147) [junit] at com.poindexter.ACTest.testRB(ACTest.java:36) [junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [junit] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) It appears to be failing on 'ReloadableResourceBundleMessageSource.resolveCodeWithoutArguments' but as soon as I remove my advice declaration it works again. It should be easily replicatable on your end.

    Spring JIRA | 1 decade ago | Victor Kolosov
    java.lang.NullPointerException
  3. 0

    Android: Saving Map State in Google map

    Stack Overflow | 11 months ago | Junie Negentien
    java.lang.RuntimeException: Unable to resume activity {com.ourThesis.junieNegentien2015/com.ourThesis.junieNegentien2015.MainActivity}: java.lang.NullPointerException
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.NullPointerException

      No message provided

      at org.springframework.context.support.ReloadableResourceBundleMessageSource.getMergedProperties()
    2. Spring Context
      AbstractMessageSource.getMessage
      1. org.springframework.context.support.ReloadableResourceBundleMessageSource.getMergedProperties(ReloadableResourceBundleMessageSource.java:295)
      2. org.springframework.context.support.ReloadableResourceBundleMessageSource.resolveCodeWithoutArguments(ReloadableResourceBundleMessageSource.java:233)
      3. org.springframework.context.support.AbstractMessageSource.getMessageInternal(AbstractMessageSource.java:207)
      4. org.springframework.context.support.AbstractMessageSource.getMessage(AbstractMessageSource.java:147)
      4 frames
    3. com.poindexter
      ACTest.testRB
      1. com.poindexter.ACTest.testRB(ACTest.java:36)
      1 frame
    4. Java RT
      DelegatingMethodAccessorImpl.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      3 frames