Weld 2.2.9: Method visibility problem with stereotype bean injection
katheris Jan 30, 2015 9:35 AMHi I am seeing a problem with some test code that I have written. I have two beans annotated with @Model, called Test1 and Test3. Test3 has an int called count and a method called getCountAntInc() which increases count and then returns it. Test1 bean has a method which has Test3 bean injected into it and calls the getcountAndInc() method. I am finding that in Weld 2.2.5 and 2.2.9 the Test1 bean seems to get an old version of Test3 bean injected. So if the method is run twice it returns a different value the second time. This problem goes away if I make getCountAndInc public. This problem does not occur in Weld 2.2.2 or the current level of glassfish. Am I missing something or is this the expected behaviour in weld 2.2.9? Thanks in advance, Katherine
Test1 |
---|
@Model public class Test1 { public Test1() { private @Inject @Default BeanManager manager; @SuppressWarnings({ "unchecked", "serial" }) public String getTestCountC() { // get a @Model WebBean with no name overrides, and make sure the count is accurate int count = 11; int step = 1; try { TypeLiteral<Test3> x = new TypeLiteral<Test3>() {}; step++; Bean<Test3> iBean = (Bean<Test3>) manager.getBeans(Test3.class, new Annotation[0]).iterator().next(); step++; Type t = x.getType(); step++; CreationalContext c = manager.createCreationalContext(iBean); step++; Test3 t3 = (Test3) manager.getReference(iBean, t, c); step++; count = t3.getCountandInc(); if (count == 33) { return "PASSED - count is: " + count; } } catch (Throwable t) { return "Caught Throwable after step: " + step + " " + t; } return "FAILED - count is: " + count; } private @Inject Test3 t3; public String getTestCountD() { // Access same @Model bean as in getTestCountC, make sure the count value was not re-initialized during this request scope operation int count = 11; try { count = t3.getCountandInc(); if (count == 34) { return "PASSED - count is: " + count; } } catch (Throwable t) { return "Caught Throwable in getTestCountA: " + t; } return "FAILED - count is: " + count; } } |
Test3 |
---|
@Model public class Test3 { int count = 135; public Test3() { count = 33; } int getCountandInc() { int oldCount = count; count++; return oldCount; } } |