You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by sb...@apache.org on 2019/11/17 21:18:12 UTC

[aries] branch trunk updated: Propagate NamingException from initial context creation failure.

This is an automated email from the ASF dual-hosted git repository.

sbratton pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/aries.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 0cc8220  Propagate NamingException from initial context creation failure.
0cc8220 is described below

commit 0cc82201ca3252dc419ecade8760ecbbdba3b408
Author: Samuel E Bratton <se...@users.noreply.github.com>
AuthorDate: Thu Nov 14 14:43:03 2019 -0600

    Propagate NamingException from initial context creation failure.
    
    Per OSGI spec
      o If an Exception is thrown by an Initial Context Factory Builder service, then this Exception must be logged but further ignored.
      o Exceptions thrown by the InitialContextFactory objects when creating a Context must be thrown to the caller.
---
 .../java/org/apache/aries/jndi/ContextHelper.java  | 37 +++++++++++-----------
 1 file changed, 19 insertions(+), 18 deletions(-)

diff --git a/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextHelper.java b/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextHelper.java
index e0b5a4d..4a69607 100644
--- a/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextHelper.java
+++ b/jndi/jndi-core/src/main/java/org/apache/aries/jndi/ContextHelper.java
@@ -181,23 +181,24 @@ public final class ContextHelper {
     }
 
     private static Optional<ContextProvider> getInitialContextUsingBuilder(BundleContext context,
-                                                                           Hashtable<?, ?> environment) {
-        for (ServiceReference<InitialContextFactoryBuilder> ref : Activator.getInitialContextFactoryBuilderServices()) {
-            InitialContextFactoryBuilder builder = Activator.getService(context, ref);
-            try {
-                InitialContextFactory factory = builder.createInitialContextFactory(environment);
-                if (factory != null) {
-                    return Optional.of(new SingleContextProvider(context, ref, factory.getInitialContext(environment)));
-                }
-            } catch (NamingException ne) {
-                // ignore this, if the builder fails we want to move onto the next one
-                logger.log(Level.FINE, "Exception caught", ne);
-            } catch (NullPointerException npe) {
-                logger.log(Level.SEVERE, "NPE caught in ContextHelper.getInitialContextUsingBuilder. context=" + context + " ref=" + ref);
-                throw npe;
-            }
-        }
-        return Optional.empty();
+    		Hashtable<?, ?> environment) throws NamingException {
+    	
+    	for (ServiceReference<InitialContextFactoryBuilder> ref : Activator.getInitialContextFactoryBuilderServices()) {
+    		InitialContextFactoryBuilder builder = Activator.getService(context, ref);
+    		InitialContextFactory factory=null;
+    		try {
+    			factory = builder.createInitialContextFactory(environment);
+    		} catch (NamingException ne) {
+    			// ignore this, if the builder fails we want to move onto the next one
+    			logger.log(Level.FINE, "Exception caught", ne);
+    		} catch (NullPointerException npe) {
+    			logger.log(Level.SEVERE, "NPE caught in ContextHelper.getInitialContextUsingBuilder. context=" + context + " ref=" + ref);
+    			throw npe;
+    		}
+    		if (factory != null) {
+    			return Optional.of(new SingleContextProvider(context, ref, factory.getInitialContext(environment)));
+    		}
+    	}
+    	return Optional.empty();
     }
-
 }