You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openwebbeans.apache.org by "Joe Bergmark (JIRA)" <ji...@apache.org> on 2009/12/09 22:57:18 UTC

[jira] Created: (OWB-185) Managed beans with non-default constructors lead to InstantiationException when creating the proxy

Managed beans with non-default constructors lead to InstantiationException when creating the proxy
--------------------------------------------------------------------------------------------------

                 Key: OWB-185
                 URL: https://issues.apache.org/jira/browse/OWB-185
             Project: OpenWebBeans
          Issue Type: Bug
          Components: Injection and Lookup
    Affects Versions: M3
            Reporter: Joe Bergmark
            Assignee: Gurkan Erdogdu


While working on OWB-151 I ran into a problem with the way proxies are created for beans with non-default injected constructors.  For example, you could look at 

org.apache.webbeans.newtests.interceptors.lifecycle.LifecycleBean and give it a normal scope:

@RequestScoped
@LifecycleBinding
@Named("org.apache.webbeans.newtests.interceptors.lifecycle.LifecycleBean")
public class LifecycleBean
{
    public static String CONSTRUCTOR_INJECTED = null; 
    
    @Inject
    public LifecycleBean(@New String string)
    {
        CONSTRUCTOR_INJECTED = string;
    }

    
    public void touch(){}
}

Leads to the following exception (the stack trace is off slightly due to some refactoring I have done but the error should be the same):
org.apache.webbeans.exception.WebBeansException: java.lang.InstantiationException: org.apache.webbeans.newtests.interceptors.lifecycle.LifecycleBean_$$_javassist_1
	at org.apache.webbeans.proxy.JavassistProxyFactory.createNewProxyWithHandler(JavassistProxyFactory.java:53)
	at org.apache.webbeans.proxy.JavassistProxyFactory.createNewProxyInstance(JavassistProxyFactory.java:78)
	at org.apache.webbeans.container.BeanManagerImpl.getReference(BeanManagerImpl.java:702)
	at org.apache.webbeans.newtests.interceptors.lifecycle.LifecycleTest.testLifecycle(LifecycleTest.java:57)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
	at java.lang.reflect.Method.invoke(Method.java:599)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
	at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.lang.InstantiationException: org.apache.webbeans.newtests.interceptors.lifecycle.LifecycleBean_$$_javassist_1
	at java.lang.J9VMInternals.newInstanceImpl(Native Method)
	at java.lang.Class.newInstance(Class.java:1325)
	at org.apache.webbeans.proxy.JavassistProxyFactory.createNewProxyWithHandler(JavassistProxyFactory.java:48)
	... 27 more



-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Re: [jira] Created: (OWB-185) Managed beans with non-default constructors lead to InstantiationException when creating the proxy

Posted by Joseph Bergmark <be...@gmail.com>.
I saw that 3.1.1 says that managed beans need to either have a default
constructor or have a constructor annotated @Inject, but I missed 5.4.1 with
the confusing double negative sentence that says that client proxies are
only valid for beans that "don't have a non-private constructor with no
parameters."

Thanks for the pointer!

Sincerely,

Joe

On Thu, Dec 10, 2009 at 1:43 AM, Gurkan Erdogdu <cg...@gmail.com>wrote:

> If a bean is normal scoped, it must satisfy conditions at  5.4.1. Mean that
> it has to default constructor.
>
> I think that I was checked this situation in our impl. in
> WebBeansUtil#checkUnproxiableApiType.
>
> We have to look where this method is called.
>
> 2009/12/9 Joe Bergmark (JIRA) <ji...@apache.org>
>
> > Managed beans with non-default constructors lead to
> InstantiationException
> > when creating the proxy
> >
> >
> --------------------------------------------------------------------------------------------------
> >
> >                 Key: OWB-185
> >                 URL: https://issues.apache.org/jira/browse/OWB-185
> >             Project: OpenWebBeans
> >          Issue Type: Bug
> >          Components: Injection and Lookup
> >    Affects Versions: M3
> >            Reporter: Joe Bergmark
> >            Assignee: Gurkan Erdogdu
> >
> >
> > While working on OWB-151 I ran into a problem with the way proxies are
> > created for beans with non-default injected constructors.  For example,
> you
> > could look at
> >
> > org.apache.webbeans.newtests.interceptors.lifecycle.LifecycleBean and
> give
> > it a normal scope:
> >
> > @RequestScoped
> > @LifecycleBinding
> >
> @Named("org.apache.webbeans.newtests.interceptors.lifecycle.LifecycleBean")
> > public class LifecycleBean
> > {
> >    public static String CONSTRUCTOR_INJECTED = null;
> >
> >    @Inject
> >    public LifecycleBean(@New String string)
> >    {
> >        CONSTRUCTOR_INJECTED = string;
> >    }
> >
> >
> >    public void touch(){}
> > }
> >
> > Leads to the following exception (the stack trace is off slightly due to
> > some refactoring I have done but the error should be the same):
> > org.apache.webbeans.exception.WebBeansException:
> > java.lang.InstantiationException:
> >
> org.apache.webbeans.newtests.interceptors.lifecycle.LifecycleBean_$$_javassist_1
> >        at
> >
> org.apache.webbeans.proxy.JavassistProxyFactory.createNewProxyWithHandler(JavassistProxyFactory.java:53)
> >        at
> >
> org.apache.webbeans.proxy.JavassistProxyFactory.createNewProxyInstance(JavassistProxyFactory.java:78)
> >        at
> >
> org.apache.webbeans.container.BeanManagerImpl.getReference(BeanManagerImpl.java:702)
> >        at
> >
> org.apache.webbeans.newtests.interceptors.lifecycle.LifecycleTest.testLifecycle(LifecycleTest.java:57)
> >        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >        at
> >
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> >        at
> >
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
> >        at java.lang.reflect.Method.invoke(Method.java:599)
> >        at
> >
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
> >        at
> >
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
> >        at
> >
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
> >        at
> >
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
> >        at
> >
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
> >        at
> >
> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
> >        at
> >
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
> >        at
> >
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
> >        at
> org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
> >        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
> >        at
> org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
> >        at
> >
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
> >        at
> >
> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
> >        at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
> >        at
> >
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
> >        at
> >
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> >        at
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
> >        at
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
> >        at
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
> >        at
> >
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
> > Caused by: java.lang.InstantiationException:
> >
> org.apache.webbeans.newtests.interceptors.lifecycle.LifecycleBean_$$_javassist_1
> >        at java.lang.J9VMInternals.newInstanceImpl(Native Method)
> >        at java.lang.Class.newInstance(Class.java:1325)
> >        at
> >
> org.apache.webbeans.proxy.JavassistProxyFactory.createNewProxyWithHandler(JavassistProxyFactory.java:48)
> >        ... 27 more
> >
> >
> >
> > --
> > This message is automatically generated by JIRA.
> > -
> > You can reply to this email to add a comment to the issue online.
> >
> >
>
>
> --
> Gurkan Erdogdu
> http://gurkanerdogdu.blogspot.com
>

Re: [jira] Created: (OWB-185) Managed beans with non-default constructors lead to InstantiationException when creating the proxy

Posted by Gurkan Erdogdu <cg...@gmail.com>.
If a bean is normal scoped, it must satisfy conditions at  5.4.1. Mean that
it has to default constructor.

I think that I was checked this situation in our impl. in
WebBeansUtil#checkUnproxiableApiType.

We have to look where this method is called.

2009/12/9 Joe Bergmark (JIRA) <ji...@apache.org>

> Managed beans with non-default constructors lead to InstantiationException
> when creating the proxy
>
> --------------------------------------------------------------------------------------------------
>
>                 Key: OWB-185
>                 URL: https://issues.apache.org/jira/browse/OWB-185
>             Project: OpenWebBeans
>          Issue Type: Bug
>          Components: Injection and Lookup
>    Affects Versions: M3
>            Reporter: Joe Bergmark
>            Assignee: Gurkan Erdogdu
>
>
> While working on OWB-151 I ran into a problem with the way proxies are
> created for beans with non-default injected constructors.  For example, you
> could look at
>
> org.apache.webbeans.newtests.interceptors.lifecycle.LifecycleBean and give
> it a normal scope:
>
> @RequestScoped
> @LifecycleBinding
> @Named("org.apache.webbeans.newtests.interceptors.lifecycle.LifecycleBean")
> public class LifecycleBean
> {
>    public static String CONSTRUCTOR_INJECTED = null;
>
>    @Inject
>    public LifecycleBean(@New String string)
>    {
>        CONSTRUCTOR_INJECTED = string;
>    }
>
>
>    public void touch(){}
> }
>
> Leads to the following exception (the stack trace is off slightly due to
> some refactoring I have done but the error should be the same):
> org.apache.webbeans.exception.WebBeansException:
> java.lang.InstantiationException:
> org.apache.webbeans.newtests.interceptors.lifecycle.LifecycleBean_$$_javassist_1
>        at
> org.apache.webbeans.proxy.JavassistProxyFactory.createNewProxyWithHandler(JavassistProxyFactory.java:53)
>        at
> org.apache.webbeans.proxy.JavassistProxyFactory.createNewProxyInstance(JavassistProxyFactory.java:78)
>        at
> org.apache.webbeans.container.BeanManagerImpl.getReference(BeanManagerImpl.java:702)
>        at
> org.apache.webbeans.newtests.interceptors.lifecycle.LifecycleTest.testLifecycle(LifecycleTest.java:57)
>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>        at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>        at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
>        at java.lang.reflect.Method.invoke(Method.java:599)
>        at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
>        at
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>        at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
>        at
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
>        at
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
>        at
> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
>        at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
>        at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
>        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
>        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
>        at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
>        at
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
>        at
> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
>        at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
>        at
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
>        at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>        at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
>        at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
>        at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
>        at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
> Caused by: java.lang.InstantiationException:
> org.apache.webbeans.newtests.interceptors.lifecycle.LifecycleBean_$$_javassist_1
>        at java.lang.J9VMInternals.newInstanceImpl(Native Method)
>        at java.lang.Class.newInstance(Class.java:1325)
>        at
> org.apache.webbeans.proxy.JavassistProxyFactory.createNewProxyWithHandler(JavassistProxyFactory.java:48)
>        ... 27 more
>
>
>
> --
> This message is automatically generated by JIRA.
> -
> You can reply to this email to add a comment to the issue online.
>
>


-- 
Gurkan Erdogdu
http://gurkanerdogdu.blogspot.com

[jira] Closed: (OWB-185) Managed beans with non-default constructors lead to InstantiationException when creating the proxy

Posted by "Gurkan Erdogdu (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OWB-185?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gurkan Erdogdu closed OWB-185.
------------------------------

       Resolution: Fixed
    Fix Version/s: M4

Look at chapter 5.4.1. Normal scoped beans must have default public constructor.

> Managed beans with non-default constructors lead to InstantiationException when creating the proxy
> --------------------------------------------------------------------------------------------------
>
>                 Key: OWB-185
>                 URL: https://issues.apache.org/jira/browse/OWB-185
>             Project: OpenWebBeans
>          Issue Type: Bug
>          Components: Injection and Lookup
>    Affects Versions: M3
>            Reporter: Joe Bergmark
>            Assignee: Gurkan Erdogdu
>             Fix For: M4
>
>
> While working on OWB-151 I ran into a problem with the way proxies are created for beans with non-default injected constructors.  For example, you could look at 
> org.apache.webbeans.newtests.interceptors.lifecycle.LifecycleBean and give it a normal scope:
> @RequestScoped
> @LifecycleBinding
> @Named("org.apache.webbeans.newtests.interceptors.lifecycle.LifecycleBean")
> public class LifecycleBean
> {
>     public static String CONSTRUCTOR_INJECTED = null; 
>     
>     @Inject
>     public LifecycleBean(@New String string)
>     {
>         CONSTRUCTOR_INJECTED = string;
>     }
>     
>     public void touch(){}
> }
> Leads to the following exception (the stack trace is off slightly due to some refactoring I have done but the error should be the same):
> org.apache.webbeans.exception.WebBeansException: java.lang.InstantiationException: org.apache.webbeans.newtests.interceptors.lifecycle.LifecycleBean_$$_javassist_1
> 	at org.apache.webbeans.proxy.JavassistProxyFactory.createNewProxyWithHandler(JavassistProxyFactory.java:53)
> 	at org.apache.webbeans.proxy.JavassistProxyFactory.createNewProxyInstance(JavassistProxyFactory.java:78)
> 	at org.apache.webbeans.container.BeanManagerImpl.getReference(BeanManagerImpl.java:702)
> 	at org.apache.webbeans.newtests.interceptors.lifecycle.LifecycleTest.testLifecycle(LifecycleTest.java:57)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
> 	at java.lang.reflect.Method.invoke(Method.java:599)
> 	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
> 	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
> 	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
> 	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
> 	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
> 	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
> 	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
> 	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
> 	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
> 	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
> 	at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
> 	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
> 	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
> 	at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
> 	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
> 	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
> Caused by: java.lang.InstantiationException: org.apache.webbeans.newtests.interceptors.lifecycle.LifecycleBean_$$_javassist_1
> 	at java.lang.J9VMInternals.newInstanceImpl(Native Method)
> 	at java.lang.Class.newInstance(Class.java:1325)
> 	at org.apache.webbeans.proxy.JavassistProxyFactory.createNewProxyWithHandler(JavassistProxyFactory.java:48)
> 	... 27 more

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.