Re: [togglz-users] NullPointerException during Spring startup

392 views
Skip to first unread message

Christian Kaltepoth

unread,
Dec 4, 2013, 7:46:09 AM12/4/13
to togglz...@googlegroups.com
Hi,

I think this issue has already been reported and is fixed in the latest snapshots.


Could you perhaps give 2.1.0-SNAPSHOT a try?

I think I'll release 2.0.1.Final with some of the latest bug fixes soon and it would be great to know if this problem is fixed in the latest snapshots.

Christian




2013/12/4 <alertc...@gmail.com>
HI,

I am using the FeatureProxyFactoryBean class toggle between the two service classes below.  The code works and the toggle feature works, but I kept on getting the NullPointerException below.  It always show up on startup.


 <bean id="aboutless" class="com.util.AboutProcessLess"/>
   

  <bean id="aboutmore" class="com.util.AboutProcessMore"/>
    

  <bean id="about" class="org.togglz.spring.proxy.FeatureProxyFactoryBean">
    <property name="feature" value="ABOUT_WITHOUT_HOSTNAME" />
    <property name="active" ref="aboutless" />
    <property name="inactive" ref="aboutmore" />
  </bean>


2013-12-03 15:26:34.452 [RMI TCP Connection(3)-127.0.0.1] DEBUG org.springframework.beans.BeanUtils - No property editor [org.springframework.data.mongodb.core.WriteResultCheckingEditor] found for type org.springframework.data.mongodb.core.WriteResultChecking according to 'Editor' suffix convention
2013-12-03 15:26:34.459 [RMI TCP Connection(3)-127.0.0.1] WARN  o.s.b.f.s.DefaultListableBeanFactory - FactoryBean threw exception from getObjectType, despite the contract saying that it should return null if the type of its object cannot be determined yet
java.lang.NullPointerException: null
at org.togglz.spring.proxy.FeatureProxyFactoryBean.getEffectiveProxyType(FeatureProxyFactoryBean.java:77) ~[togglz-spring-2.0.0.Final.jar:na]
at org.togglz.spring.proxy.FeatureProxyFactoryBean.getObjectType(FeatureProxyFactoryBean.java:102) ~[togglz-spring-2.0.0.Final.jar:na]
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getTypeForFactoryBean(FactoryBeanRegistrySupport.java:65) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:713) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:523) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:357) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:335) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:322) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBeanNamesForType(AbstractApplicationContext.java:1174) [spring-context-3.2.3.RELEASE.jar:3.2.3.RELEASE]


The problem caused by the method below from the class FeatureProxyFactoryBean


private Class<?> getEffectiveProxyType() {

        // prefer the business interface manually set by the user
        if (proxyType != null) {
            return proxyType;
        }

        // check which interfaces the both delegates implements
        HashSet<Class<?>> activeInterfaces = new HashSet<Class<?>>(Arrays.asList(active.getClass().getInterfaces()));
        HashSet<Class<?>> inactiveInterfaces = new HashSet<Class<?>>(Arrays.asList(inactive.getClass().getInterfaces()));

        // build the intersection
        activeInterfaces.retainAll(inactiveInterfaces);

        // we need exactly one interface to share
        if (activeInterfaces.size() != 1) {
            throw new IllegalArgumentException("The active and the inactive class must share exactly one interface");
        }

        return activeInterfaces.iterator().next();

    }

During Spring initialization all the properties in FeatureProxyFactoryBean are nulls.  when active.getClass() is called, it caused a NullPointerException.

I wonder if anybody have seen this problem?

To fix this I have added:


package com.util.togglz;

import org.togglz.spring.proxy.FeatureProxyFactoryBean;

public class MyFeatureProxyFactoryBean extends FeatureProxyFactoryBean
{
  @Override
  public Class<?> getObjectType()
  {
    if (this.getProxyType() == null)
    {
      return null;
    }

    return super.getObjectType();
  }
}

and in the xml file I used:


  <bean id="about" class="com.util.togglz.MyFeatureProxyFactoryBean ">
    <property name="feature" value="ABOUT_WITHOUT_HOSTNAME" />
    <property name="active" ref="aboutless" />
    <property name="inactive" ref="aboutmore" />
  </bean>

This fixed the NullPointerException, but is this the best way to solve this?

Please advise.  Thanks.

Don




--
Christian Kaltepoth

alertc...@gmail.com

unread,
Dec 4, 2013, 2:34:53 PM12/4/13
to togglz...@googlegroups.com
Thanks Christian.  I will give the snapshots a try then.  Thanks again.

Don

Christian Kaltepoth

unread,
Dec 5, 2013, 3:37:53 AM12/5/13
to togglz...@googlegroups.com
Great. Let me know if the snapshots work for you. :)

Christian

Mark Madine

unread,
Dec 5, 2013, 4:50:11 PM12/5/13
to togglz...@googlegroups.com
Christian,

Is there another repo for the snapshot?

Sonatype looks incomplete for 2.1.0-SNAPSHOT



Mark.

Christian Kaltepoth

unread,
Dec 6, 2013, 1:52:37 AM12/6/13
to togglz...@googlegroups.com
Hmmm. That's weird. The search results show "2.0.0.Final" as the latest version for togglz-core, but clicking on "Show all versions" reveals that there is "2.1.0-SNAPSHOT":


Seems to be some Nexus problem. Could you try to set the version to "2.1.0-SNAPSHOT" in your pom. I guess Maven will be able to download the correct dependencies in this case.

Let me know if it doesn't work.

Christian
 


2013/12/5 Mark Madine <mad...@gmail.com>

Mark Madine

unread,
Dec 9, 2013, 10:17:24 AM12/9/13
to togglz...@googlegroups.com
I was able to pull down 2.1.0-SNAPSHOT.


thanks
Mark.

Christian Kaltepoth

unread,
Dec 9, 2013, 10:30:32 AM12/9/13
to togglz...@googlegroups.com
Awesome! Thanks. :)


2013/12/9 Mark Madine <mad...@gmail.com>
Reply all
Reply to author
Forward
0 new messages