Skip to content

Commit

Permalink
Refactor to use currently dead code as originally intended
Browse files Browse the repository at this point in the history
  • Loading branch information
markt-asf committed Apr 21, 2018
1 parent 73a5130 commit 2bc74b8
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions api/client/src/main/java/javax/websocket/ContainerProvider.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2012, 2017 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2017 Oracle and/or its affiliates and others.
* All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -16,6 +17,7 @@

package javax.websocket;

import java.util.Iterator;
import java.util.ServiceLoader;

/**
Expand All @@ -39,17 +41,18 @@ public abstract class ContainerProvider {
* @return an implementation provided instance of type WebSocketContainer
*/
public static WebSocketContainer getWebSocketContainer() {
WebSocketContainer wsc = null;
for (ContainerProvider impl : ServiceLoader.load(ContainerProvider.class)) {
wsc = impl.getContainer();
if (wsc != null) {
return wsc;
}
}
if (wsc == null) {
throw new RuntimeException("Could not find an implementation class.");
} else {
Iterator<ContainerProvider> providers = ServiceLoader.load(ContainerProvider.class).iterator();
if (providers.hasNext()) {
do {
ContainerProvider impl = providers.next();
WebSocketContainer wsc = impl.getContainer();
if (wsc != null) {
return wsc;
}
} while (providers.hasNext());
throw new RuntimeException("Could not find an implementation class with a non-null WebSocketContainer.");
} else {
throw new RuntimeException("Could not find an implementation class.");
}
}

Expand Down

0 comments on commit 2bc74b8

Please sign in to comment.