[JBoss JIRA] (CDI-45) Optional Injection Points
by John Ament (JIRA)
[ https://issues.jboss.org/browse/CDI-45?page=com.atlassian.jira.plugin.sys... ]
John Ament edited comment on CDI-45 at 10/12/16 6:38 AM:
---------------------------------------------------------
I'm -1 for adding a method named {{getOptional}} but might be +0.5 on methods like {{optional()}} or {{asOptional()}} since from a callers point of view the chained method calls don't necessarily create new objects.
It would be more ideal if the {{Instance}} object dealt with missing beans better, which is really what this ticket should cover. I think I'm strongly +1 on adding at least an {{isPresent()}} (the opposite of {{isUnresolved()}} effectively being a positive check rather than those negative checks) and an {{ifPresent(Consumer<T>)}} method.
was (Author: meetoblivion):
I'm -1 for adding a method named {{getOptional}} but might be +0.5 on methods like {{optional()}} or {{asOptional()}} since from a callers point of view
It would be more ideal if the {{Instance}} object dealt with missing beans better, which is really what this ticket should cover. I think I'm strongly +1 on adding at least an {{isPresent()}} (the opposite of {{isUnresolved()}} effectively being a positive check rather than those negative checks) and an {{ifPresent(Consumer<T>)}} method.
> Optional Injection Points
> -------------------------
>
> Key: CDI-45
> URL: https://issues.jboss.org/browse/CDI-45
> Project: CDI Specification Issues
> Issue Type: Feature Request
> Components: Resolution
> Affects Versions: 1.0
> Reporter: Stuart Douglas
> Priority: Optional
> Fix For: TBD
>
>
> There are occoasions where it may be useful for some injection points to be optional, e.g.
> @Inject
> @Optional
> MyBean bean;
> This would behave the same as a normal injection point, however it will not cause the deployment to fail if it is not satisified.
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
8 years, 2 months
[JBoss JIRA] (CDI-45) Optional Injection Points
by John Ament (JIRA)
[ https://issues.jboss.org/browse/CDI-45?page=com.atlassian.jira.plugin.sys... ]
John Ament commented on CDI-45:
-------------------------------
I'm -1 for adding a method named {{getOptional}} but might be +0.5 on methods like {{optional()}} or {{asOptional()}} since from a callers point of view
It would be more ideal if the {{Instance}} object dealt with missing beans better, which is really what this ticket should cover. I think I'm strongly +1 on adding at least an {{isPresent()}} (the opposite of {{isUnresolved()}} effectively being a positive check rather than those negative checks) and an {{ifPresent(Consumer<T>)}} method.
> Optional Injection Points
> -------------------------
>
> Key: CDI-45
> URL: https://issues.jboss.org/browse/CDI-45
> Project: CDI Specification Issues
> Issue Type: Feature Request
> Components: Resolution
> Affects Versions: 1.0
> Reporter: Stuart Douglas
> Priority: Optional
> Fix For: TBD
>
>
> There are occoasions where it may be useful for some injection points to be optional, e.g.
> @Inject
> @Optional
> MyBean bean;
> This would behave the same as a normal injection point, however it will not cause the deployment to fail if it is not satisified.
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
8 years, 2 months
Re: [cdi-dev] [JBoss JIRA] (CDI-45) Optional Injection Points
by Werner Keil
In the Java SE 8 specific JSR 363 implementation Otavio and I tried to use
Optional, but see the comments in
https://github.com/unitsofmeasurement/uom-se/blob/master/src/main/java/te...
it caused problems with the type-safe Quantity mechanism.
Can't recall the exact details, but there must have been a conflict when
using another generic type like Quantity<Q> or similar as <T> of Optional.
If the <T> of Bean<T> and Optional<T> were exactly the same it might work,
but if types with their own generic elements (Collection, Map or a
combination of several with different or nested generics) are used,
Optional seems to have some problems and limitations.
So trying to add these methods could be safer based on my experience with
Optional.
Werner
On Wed, Oct 12, 2016 at 10:43 AM, <cdi-dev-request(a)lists.jboss.org> wrote:
> Send cdi-dev mailing list submissions to
> cdi-dev(a)lists.jboss.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://lists.jboss.org/mailman/listinfo/cdi-dev
> or, via email, send a message with subject or body 'help' to
> cdi-dev-request(a)lists.jboss.org
>
> You can reach the person managing the list at
> cdi-dev-owner(a)lists.jboss.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of cdi-dev digest..."
>
>
> Today's Topics:
>
> 1. [JBoss JIRA] (CDI-45) Optional Injection Points
> (John Ament (JIRA))
> 2. [JBoss JIRA] (CDI-45) Optional Injection Points
> (Martin Kouba (JIRA))
> 3. [JBoss JIRA] (CDI-45) Optional Injection Points
> (John Ament (JIRA))
> 4. [JBoss JIRA] (CDI-45) Optional Injection Points
> (Martin Kouba (JIRA))
> 5. [JBoss JIRA] (CDI-489) NonexistentConversationException
> thrown at restore view or not? (Tomas Remes (JIRA))
> 6. [JBoss JIRA] (CDI-45) Optional Injection Points
> (Matej Novotny (JIRA))
> 7. Moving on SERVLET_SPEC-116 (giving servlet beans to servlet
> spec) (Antoine Sabot-Durand)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Tue, 11 Oct 2016 16:50:00 -0400 (EDT)
> From: "John Ament (JIRA)" <issues(a)jboss.org>
> Subject: [cdi-dev] [JBoss JIRA] (CDI-45) Optional Injection Points
> To: cdi-dev(a)lists.jboss.org
> Message-ID:
> <JIRA.12428685.1295838622000.12490.1476219000927(a)Atlassian.JIRA>
> Content-Type: text/plain; charset=UTF-8
>
>
> [ https://issues.jboss.org/browse/CDI-45?page=com.
> atlassian.jira.plugin.system.issuetabpanels:comment-
> tabpanel&focusedCommentId=13305781#comment-13305781 ]
>
> John Ament commented on CDI-45:
> -------------------------------
>
> I really like the idea of {{@Inject Optional<T>}}. I may try to prototype
> a CDI extension that does it.
>
> > Optional Injection Points
> > -------------------------
> >
> > Key: CDI-45
> > URL: https://issues.jboss.org/browse/CDI-45
> > Project: CDI Specification Issues
> > Issue Type: Feature Request
> > Components: Resolution
> > Affects Versions: 1.0
> > Reporter: Stuart Douglas
> > Priority: Optional
> > Fix For: TBD
> >
> >
> > There are occoasions where it may be useful for some injection points to
> be optional, e.g.
> > @Inject
> > @Optional
> > MyBean bean;
> > This would behave the same as a normal injection point, however it will
> not cause the deployment to fail if it is not satisified.
>
>
>
> --
> This message was sent by Atlassian JIRA
> (v6.4.11#64026)
>
>
> ------------------------------
>
> Message: 2
> Date: Tue, 11 Oct 2016 17:21:00 -0400 (EDT)
> From: "Martin Kouba (JIRA)" <issues(a)jboss.org>
> Subject: [cdi-dev] [JBoss JIRA] (CDI-45) Optional Injection Points
> To: cdi-dev(a)lists.jboss.org
> Message-ID:
> <JIRA.12428685.1295838622000.12514.1476220860783(a)Atlassian.JIRA>
> Content-Type: text/plain; charset=UTF-8
>
>
> [ https://issues.jboss.org/browse/CDI-45?page=com.
> atlassian.jira.plugin.system.issuetabpanels:comment-
> tabpanel&focusedCommentId=13305785#comment-13305785 ]
>
> Martin Kouba commented on CDI-45:
> ---------------------------------
>
> Note that {{Optional}} is not {{Serializable}} and is defined final. So
> there will be problems with injecting into beans with passivating scope
> (e.g. {{@SessionScoped}}).
>
> > Optional Injection Points
> > -------------------------
> >
> > Key: CDI-45
> > URL: https://issues.jboss.org/browse/CDI-45
> > Project: CDI Specification Issues
> > Issue Type: Feature Request
> > Components: Resolution
> > Affects Versions: 1.0
> > Reporter: Stuart Douglas
> > Priority: Optional
> > Fix For: TBD
> >
> >
> > There are occoasions where it may be useful for some injection points to
> be optional, e.g.
> > @Inject
> > @Optional
> > MyBean bean;
> > This would behave the same as a normal injection point, however it will
> not cause the deployment to fail if it is not satisified.
>
>
>
> --
> This message was sent by Atlassian JIRA
> (v6.4.11#64026)
>
>
> ------------------------------
>
> Message: 3
> Date: Tue, 11 Oct 2016 18:38:00 -0400 (EDT)
> From: "John Ament (JIRA)" <issues(a)jboss.org>
> Subject: [cdi-dev] [JBoss JIRA] (CDI-45) Optional Injection Points
> To: cdi-dev(a)lists.jboss.org
> Message-ID:
> <JIRA.12428685.1295838622000.12589.1476225480575(a)Atlassian.JIRA>
> Content-Type: text/plain; charset=UTF-8
>
>
> [ https://issues.jboss.org/browse/CDI-45?page=com.
> atlassian.jira.plugin.system.issuetabpanels:comment-
> tabpanel&focusedCommentId=13305798#comment-13305798 ]
>
> John Ament commented on CDI-45:
> -------------------------------
>
> Underestood. The way I see it, for each Bean of type {{<T>}} there exists
> a Bean of type {{Optional<T>}} that shares the same qualifiers but has
> scope dependent. Optional beans can't be looked up programmatically.
>
> Another way to do this is to add all methods from https://docs.oracle.com/
> javase/8/docs/api/java/util/Optional.html to Instance, which would be:
>
> * ifPresent
> * isPresent
> * orElse
> * orElseGet
> * orElseThrow
>
> So hm.
>
> > Optional Injection Points
> > -------------------------
> >
> > Key: CDI-45
> > URL: https://issues.jboss.org/browse/CDI-45
> > Project: CDI Specification Issues
> > Issue Type: Feature Request
> > Components: Resolution
> > Affects Versions: 1.0
> > Reporter: Stuart Douglas
> > Priority: Optional
> > Fix For: TBD
> >
> >
> > There are occoasions where it may be useful for some injection points to
> be optional, e.g.
> > @Inject
> > @Optional
> > MyBean bean;
> > This would behave the same as a normal injection point, however it will
> not cause the deployment to fail if it is not satisified.
>
>
>
> --
> This message was sent by Atlassian JIRA
> (v6.4.11#64026)
>
>
> ------------------------------
>
> Message: 4
> Date: Wed, 12 Oct 2016 02:11:01 -0400 (EDT)
> From: "Martin Kouba (JIRA)" <issues(a)jboss.org>
> Subject: [cdi-dev] [JBoss JIRA] (CDI-45) Optional Injection Points
> To: cdi-dev(a)lists.jboss.org
> Message-ID:
> <JIRA.12428685.1295838622000.12813.1476252661033(a)Atlassian.JIRA>
> Content-Type: text/plain; charset=UTF-8
>
>
> [ https://issues.jboss.org/browse/CDI-45?page=com.
> atlassian.jira.plugin.system.issuetabpanels:comment-
> tabpanel&focusedCommentId=13305826#comment-13305826 ]
>
> Martin Kouba commented on CDI-45:
> ---------------------------------
>
> -1 for adding those methods on {{Instance}} and -1 for introducing
> {{Optional}} built-in bean (mainly due to serialization issues and the need
> for special handling, e.g. disallow programatic lookup).
> {{Instance.getOptional().ifPresent(...)}} etc. is imho easier to
> understand.
>
> > Optional Injection Points
> > -------------------------
> >
> > Key: CDI-45
> > URL: https://issues.jboss.org/browse/CDI-45
> > Project: CDI Specification Issues
> > Issue Type: Feature Request
> > Components: Resolution
> > Affects Versions: 1.0
> > Reporter: Stuart Douglas
> > Priority: Optional
> > Fix For: TBD
> >
> >
> > There are occoasions where it may be useful for some injection points to
> be optional, e.g.
> > @Inject
> > @Optional
> > MyBean bean;
> > This would behave the same as a normal injection point, however it will
> not cause the deployment to fail if it is not satisified.
>
>
>
> --
> This message was sent by Atlassian JIRA
> (v6.4.11#64026)
>
> _______________________________________________
> cdi-dev mailing list
> cdi-dev(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/cdi-dev
>
> Note that for all code provided on this list, the provider licenses the
> code under the Apache License, Version 2 (http://www.apache.org/
> licenses/LICENSE-2.0.html). For all other ideas provided on this list,
> the provider waives all patent and other intellectual property rights
> inherent in such information.
>
> End of cdi-dev Digest, Vol 71, Issue 25
> ***************************************
>
8 years, 2 months
[JBoss JIRA] (CDI-637) Rename builder package to configurator
by Antoine Sabot-Durand (JIRA)
Antoine Sabot-Durand created CDI-637:
----------------------------------------
Summary: Rename builder package to configurator
Key: CDI-637
URL: https://issues.jboss.org/browse/CDI-637
Project: CDI Specification Issues
Issue Type: Bug
Affects Versions: 2.0-EDR2
Reporter: Antoine Sabot-Durand
Since it contains only confgurators, package {{javax.enterprise.inject.spi.builder}} should be renamed {{javax.enterprise.inject.spi.configurator}}
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
8 years, 2 months
[JBoss JIRA] (CDI-45) Optional Injection Points
by Matej Novotny (JIRA)
[ https://issues.jboss.org/browse/CDI-45?page=com.atlassian.jira.plugin.sys... ]
Matej Novotny commented on CDI-45:
----------------------------------
-1 for {{Optional}} built-in bean, the limitations of that approach and the confusion caused (Optional vs Instance) are just not worth the few methods.
Adding all methods onto {{Instance}} just feels dirty; -10.
Personally I think explicitly supporting {{Optional}} isn't really worth it. But if we want to go that way anyway, I'd be +1 for adding {{Instance.getOptional}}.
> Optional Injection Points
> -------------------------
>
> Key: CDI-45
> URL: https://issues.jboss.org/browse/CDI-45
> Project: CDI Specification Issues
> Issue Type: Feature Request
> Components: Resolution
> Affects Versions: 1.0
> Reporter: Stuart Douglas
> Priority: Optional
> Fix For: TBD
>
>
> There are occoasions where it may be useful for some injection points to be optional, e.g.
> @Inject
> @Optional
> MyBean bean;
> This would behave the same as a normal injection point, however it will not cause the deployment to fail if it is not satisified.
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
8 years, 2 months
[JBoss JIRA] (CDI-489) NonexistentConversationException thrown at restore view or not?
by Tomas Remes (JIRA)
[ https://issues.jboss.org/browse/CDI-489?page=com.atlassian.jira.plugin.sy... ]
Tomas Remes commented on CDI-489:
---------------------------------
PR sent: https://github.com/cdi-spec/cdi/pull/312
> NonexistentConversationException thrown at restore view or not?
> ---------------------------------------------------------------
>
> Key: CDI-489
> URL: https://issues.jboss.org/browse/CDI-489
> Project: CDI Specification Issues
> Issue Type: Clarification
> Components: Javadoc and API
> Affects Versions: 1.2.Final
> Reporter: Vsevolod Golovanov
> Fix For: 2.0 .Final
>
>
> The 1.0 spec says in 6.7.4:
> {quote}If the propagated conversation cannot be restored, the container must associate the request with a new transient conversation and throw an exception of type javax.enterprise.context.NonexistentConversationException from the restore
> view phase of the JSF lifecycle. The application may handle this exception using the JSF ExceptionHandler.{quote}
> 1.1 and 1.2 just say:
> {quote}
> If the propagated conversation cannot be restored, the container must associate the request with a new transient conversation and
> throw an exception of type javax.enterprise.context.NonexistentConversationException.
> {quote}
> Yet the javadoc of NonexistentConversationException for both 1.1 and 1.2 says:
> {quote}
> If the propagated conversation cannot be restored, the container must associate the request with a new transient conversation and throw an exception of type NonexistentConversationException from the restore view phase of the JSF lifecycle.
> {quote}
> So is it supposed to be thrown from restore view or not? I assume not. Probably javadoc should be amended.
> I'm curious about reasoning behind the change. I tried searching for an explanation but didn't find anything.
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
8 years, 2 months
[JBoss JIRA] (CDI-45) Optional Injection Points
by Martin Kouba (JIRA)
[ https://issues.jboss.org/browse/CDI-45?page=com.atlassian.jira.plugin.sys... ]
Martin Kouba commented on CDI-45:
---------------------------------
-1 for adding those methods on {{Instance}} and -1 for introducing {{Optional}} built-in bean (mainly due to serialization issues and the need for special handling, e.g. disallow programatic lookup). {{Instance.getOptional().ifPresent(...)}} etc. is imho easier to understand.
> Optional Injection Points
> -------------------------
>
> Key: CDI-45
> URL: https://issues.jboss.org/browse/CDI-45
> Project: CDI Specification Issues
> Issue Type: Feature Request
> Components: Resolution
> Affects Versions: 1.0
> Reporter: Stuart Douglas
> Priority: Optional
> Fix For: TBD
>
>
> There are occoasions where it may be useful for some injection points to be optional, e.g.
> @Inject
> @Optional
> MyBean bean;
> This would behave the same as a normal injection point, however it will not cause the deployment to fail if it is not satisified.
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
8 years, 2 months
[JBoss JIRA] (CDI-45) Optional Injection Points
by John Ament (JIRA)
[ https://issues.jboss.org/browse/CDI-45?page=com.atlassian.jira.plugin.sys... ]
John Ament commented on CDI-45:
-------------------------------
Underestood. The way I see it, for each Bean of type {{<T>}} there exists a Bean of type {{Optional<T>}} that shares the same qualifiers but has scope dependent. Optional beans can't be looked up programmatically.
Another way to do this is to add all methods from https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html to Instance, which would be:
* ifPresent
* isPresent
* orElse
* orElseGet
* orElseThrow
So hm.
> Optional Injection Points
> -------------------------
>
> Key: CDI-45
> URL: https://issues.jboss.org/browse/CDI-45
> Project: CDI Specification Issues
> Issue Type: Feature Request
> Components: Resolution
> Affects Versions: 1.0
> Reporter: Stuart Douglas
> Priority: Optional
> Fix For: TBD
>
>
> There are occoasions where it may be useful for some injection points to be optional, e.g.
> @Inject
> @Optional
> MyBean bean;
> This would behave the same as a normal injection point, however it will not cause the deployment to fail if it is not satisified.
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
8 years, 2 months
[JBoss JIRA] (CDI-45) Optional Injection Points
by Martin Kouba (JIRA)
[ https://issues.jboss.org/browse/CDI-45?page=com.atlassian.jira.plugin.sys... ]
Martin Kouba commented on CDI-45:
---------------------------------
Note that {{Optional}} is not {{Serializable}} and is defined final. So there will be problems with injecting into beans with passivating scope (e.g. {{@SessionScoped}}).
> Optional Injection Points
> -------------------------
>
> Key: CDI-45
> URL: https://issues.jboss.org/browse/CDI-45
> Project: CDI Specification Issues
> Issue Type: Feature Request
> Components: Resolution
> Affects Versions: 1.0
> Reporter: Stuart Douglas
> Priority: Optional
> Fix For: TBD
>
>
> There are occoasions where it may be useful for some injection points to be optional, e.g.
> @Inject
> @Optional
> MyBean bean;
> This would behave the same as a normal injection point, however it will not cause the deployment to fail if it is not satisified.
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
8 years, 2 months