#1116 new
Michele Mauro

Calling more than once Injector.inject(...) overwrites already injected values

Reported by Michele Mauro | September 20th, 2011 @ 07:49 AM

When Injector.inject(BeanSource source) is called more than once at startup (for example, by two different plugins), the second call overwrites what written by the first one.

Framework version:
1.2.3 and before

Platform you're using:
Windows7 Java6, but it's not platform specific.

Reproduction steps:
Call Injector.inject with at least two different BeanSources

Details:
The problem happens because Injector.inject uses the following line:

field.set(null, source.getBeanOfType(type));

to set the value in every field. During the second run, the second BeanSource returns null for each field it doesn't know about, so the values set by the first plugin get erased. The Injector should instead do:

Object target= source.getBeanOfType(type);
... if (target!=null)
field.set(null,target);

this way, if there is more than one BeanSource, they wouldn't trample each other.
I'll add a test and maybe a pull request later.
This doesn't seem to be a heavily used feature, but it is much faster and simpler than using a DI module.

Comments and changes to this ticket

  • Michele Mauro

    Michele Mauro September 21st, 2011 @ 08:50 AM

    Attached there is a sample project that demonstrates the issue. The ApplicationTest functional test fails because one of the injected variables is resetted to null by the second Injector.inject call.
    With the bug corrected, the test should work.

  • Michael K

    Michael K June 20th, 2018 @ 12:00 PM

    I am glad to see that you have shared a very appreciated australian essays topic. This helped me a lot to understand about this project. I will highly recommend this article to others so they will get the elucidation out of it as well.

  • PaulWright

    PaulWright July 6th, 2018 @ 11:27 AM

    It's that straightforward on the grounds that the most widely recognized infused benefit is an occurrence of a class. Be that as it may, only one out of every odd reliance can be fulfilled by assignment service making another example of a class. You need other ways to deliver dependency values and that means you need other ways to specify a provider.

  • Corey Henry

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2>Play framework</h2>

Play makes it easier to build Web applications with Java. It is a clean alternative to bloated Enterprise Java stacks. It focuses on developer productivity and targets RESTful architectures. Learn more on the <a href="http://www.playframework.org">http://www.playframework.org</a> website.<br><br>

<h2>Source code is hosted on github</h2>Check out our repository at <a href="http://github.com/playframework/play">http://github.com/playframework/play</a><br><br>

<h2>Contributing, creating a patch</h2> Please read the <a href="http://play.lighthouseapp.com/projects/57987/contributor-guide">contributor guide</a><br><br>

<h2>Reporting Security Vulnerabilities</h2> Since all bug reports are public, please report any security vulnerability directly to <em>guillaume dot bort at gmail dot com</em>.<br><br>

<h2>Creating a bug report</h2> Bug reports are incredibly helpful, so take time to report bugs and request features in our ticket tracker. We’re always grateful for patches to Play’s code. Indeed, bug reports with attached patches will get fixed far quickly than those without any.<br><br>

Please include as much relevant information as possible including the exact framework version you're using and a code snippet that reproduces the problem.<br><br>

Don't have too much expectations. Unless the bug is really a serious "everything is broken" thing, you're creating a ticket to start a discussion. Having a patch (or a branch on Github we can pull from) is better, but then again we'll only pull high quality branches that make sense to be in the core of Play.

People watching this ticket

Attachments

Referenced by

Pages