Skip to content

Commit

Permalink
fix #537 : remove npe from ContainerNotAvailableException
Browse files Browse the repository at this point in the history
  • Loading branch information
marevol committed Jun 10, 2016
1 parent 453db85 commit 26df9e4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,24 @@ public class ContainerNotAvailableException extends FessSystemException {

private static final long serialVersionUID = 1L;

private String componentName;

public ContainerNotAvailableException(final String componentName) {
super(componentName + " is not available.");
}

public ContainerNotAvailableException(final String componentName, final Throwable cause) {
super(componentName + " is not available.", cause);
this.componentName = componentName;
}

public ContainerNotAvailableException(final Throwable cause) {
super(cause);
super("Container is not avaiable.");
this.componentName = "container";
}

public String getComponentName() {
return componentName;
}

}
10 changes: 10 additions & 0 deletions src/main/java/org/codelibs/fess/indexer/IndexUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.codelibs.fess.es.client.FessEsClient;
import org.codelibs.fess.es.log.exbhv.ClickLogBhv;
import org.codelibs.fess.es.log.exbhv.FavoriteLogBhv;
import org.codelibs.fess.exception.ContainerNotAvailableException;
import org.codelibs.fess.exception.FessSystemException;
import org.codelibs.fess.helper.IndexingHelper;
import org.codelibs.fess.helper.IntervalControlHelper;
Expand Down Expand Up @@ -287,9 +288,18 @@ public void run() {
if (logger.isDebugEnabled()) {
logger.debug("Finished indexUpdater.");
}
} catch (final ContainerNotAvailableException e) {
if (logger.isDebugEnabled()) {
logger.error("IndexUpdater is terminated.", e);
} else if (logger.isInfoEnabled()) {
logger.info("IndexUpdater is terminated.");
}
forceStop();
} catch (final Throwable t) {
if (ComponentUtil.available()) {
logger.error("IndexUpdater is terminated.", t);
} else if (logger.isDebugEnabled()) {
logger.error("IndexUpdater is terminated.", t);
} else if (logger.isInfoEnabled()) {
logger.info("IndexUpdater is terminated.");
}
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/org/codelibs/fess/util/ComponentUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@
import org.lastaflute.di.core.smart.hot.HotdeployUtil;
import org.lastaflute.job.JobManager;
import org.lastaflute.web.servlet.request.RequestManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class ComponentUtil {
private static final Logger logger = LoggerFactory.getLogger(ComponentUtil.class);

private static final String PERMISSION_HELPER = "permissionHelper";

Expand Down Expand Up @@ -345,15 +348,23 @@ public static <T> T getComponent(final Class<T> clazz) {
try {
return SingletonLaContainer.getComponent(clazz);
} catch (final NullPointerException e) {
throw new ContainerNotAvailableException(e);
if (logger.isDebugEnabled()) {
throw new ContainerNotAvailableException(clazz.getCanonicalName(), e);
} else {
throw new ContainerNotAvailableException(clazz.getCanonicalName());
}
}
}

public static <T> T getComponent(final String componentName) {
try {
return SingletonLaContainer.getComponent(componentName);
} catch (final NullPointerException e) {
throw new ContainerNotAvailableException(e);
if (logger.isDebugEnabled()) {
throw new ContainerNotAvailableException(componentName, e);
} else {
throw new ContainerNotAvailableException(componentName);
}
}
}

Expand Down

0 comments on commit 26df9e4

Please # to comment.