You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by "CptBartender (via GitHub)" <gi...@apache.org> on 2026/06/10 14:57:53 UTC

[PR] Refactored usage of Optional<> as method parameters [karaf]

CptBartender opened a new pull request, #2720:
URL: https://github.com/apache/karaf/pull/2720

   There's only one place that uses `Optional` as method parameters, and it is generally recommended to be avioded. I've reworked the use case so that the `Optional`s are no longer used as method parameters or generic parameters for other functional interfaces


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@karaf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Refactored usage of Optional<> as method parameters [karaf]

Posted by "CptBartender (via GitHub)" <gi...@apache.org>.
CptBartender commented on code in PR #2720:
URL: https://github.com/apache/karaf/pull/2720#discussion_r3927556872


##########
config/core/src/main/java/org/apache/karaf/config/core/MetaServiceCaller.java:
##########
@@ -73,13 +72,15 @@ public static List<String> getPidsWithMetaInfo(BundleContext context) {
      * Attempts to find MetaType information for the specified PID and 
      * invokes the supplied callback with the result of the search   
      */
-    public static <T> T doWithMetaType(BundleContext context, String pid, Function<Optional<MetaInfo>, T> function) {
+    public static <T> T doWithMetaType(BundleContext context, String pid, Function<MetaInfo, T> function) {
         ServiceReference<MetaTypeService> ref = context.getServiceReference(MetaTypeService.class);
         if (ref != null) {
             try {
                 MetaTypeService metaService = context.getService(ref);
                 MetaInfo metaInfo = getMetatype(context, metaService, pid);
-                return function.apply(Optional.ofNullable(metaInfo));
+                if (metaInfo != null) {

Review Comment:
   Good catch - fixed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@karaf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Refactored usage of Optional<> as method parameters [karaf]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #2720:
URL: https://github.com/apache/karaf/pull/2720#issuecomment-5531226077

   ## Test Results
     702 files  ±0    702 suites  ±0   1h 17m 33s ⏱️ - 2m 46s
     932 tests ±0    884 ✅ ±0   48 💤 ±0  0 ❌ ±0 
   2 796 runs  ±0  2 652 ✅ ±0  144 💤 ±0  0 ❌ ±0 
   
   Results for commit 06dec493. ± Comparison against base commit 9e8d6e1d.
   
   [test-results]:data:application/gzip;base64,H4sIANHOmWoC/03Oyw7CIBCF4VdpWLug0ymlvoxBLgmxLYbLyvjuTrVgl/834YQXc36xiV27icOlY6n4fEpToso+bAQoxoGErnm/zwPUuqWiNZGU+KeHf+6PZBOn/ELCG9gYQzwklm0fhWkWR9VRECM0+o32iFVOo98+b+qwrj5TMC6M1Ug/diMCGAU4O9NLobixdgCJ7g4AXLD3Bx+bOTYPAQAA
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@karaf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Refactored usage of Optional<> as method parameters [karaf]

Posted by "holgerfriedrich (via GitHub)" <gi...@apache.org>.
holgerfriedrich commented on code in PR #2720:
URL: https://github.com/apache/karaf/pull/2720#discussion_r3835993956


##########
config/core/src/main/java/org/apache/karaf/config/core/MetaServiceCaller.java:
##########
@@ -73,13 +72,15 @@ public static List<String> getPidsWithMetaInfo(BundleContext context) {
      * Attempts to find MetaType information for the specified PID and 
      * invokes the supplied callback with the result of the search   
      */
-    public static <T> T doWithMetaType(BundleContext context, String pid, Function<Optional<MetaInfo>, T> function) {
+    public static <T> T doWithMetaType(BundleContext context, String pid, Function<MetaInfo, T> function) {
         ServiceReference<MetaTypeService> ref = context.getServiceReference(MetaTypeService.class);
         if (ref != null) {
             try {
                 MetaTypeService metaService = context.getService(ref);
                 MetaInfo metaInfo = getMetatype(context, metaService, pid);
-                return function.apply(Optional.ofNullable(metaInfo));
+                if (metaInfo != null) {

Review Comment:
   This change seems to have an effect on semantics for the null case: before, `function.apply` of an empty `Optional` was returned, now the fall-through may just return null.
   This could lead to an NPE in the statement from the other file above (`return MetaServiceCaller.doWithMetaType(...)`).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@karaf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Refactored usage of Optional<> as method parameters [karaf]

Posted by "jbonofre (via GitHub)" <gi...@apache.org>.
jbonofre merged PR #2720:
URL: https://github.com/apache/karaf/pull/2720


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@karaf.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org