Skip to content

Commit

Permalink
Code Quality Improvement - Exception handlers should preserve the ori…
Browse files Browse the repository at this point in the history
…ginal exception

Update

Code Quality Improvement -  Update with logger.debug
  • Loading branch information
civanyp committed Dec 4, 2015
1 parent 01079f5 commit 06ce603
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private void loadAndPut(String environment) {
properties.load(resource);
LOG.debug("File {}.properties loaded", environment);
} catch (NullPointerException | IOException whenNotFound) {
LOG.warn("Could not find the file " + environment + ".properties to load.");
LOG.warn("Could not find the file " + environment + ".properties to load.", whenNotFound);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import java.util.Map;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
Expand Down Expand Up @@ -50,6 +53,8 @@
@RequestScoped
public class VRaptorInstantiator implements InstantiatorWithErrors, Instantiator<Object> {

private static final Logger logger = LoggerFactory.getLogger(VRaptorInstantiator.class);

private MultiInstantiator multiInstantiator;
private List<Message> errors;

Expand Down Expand Up @@ -164,8 +169,10 @@ public Object instantiate(Target<?> target, Parameters parameters) {

return converterForTarget(target).convert(parameter.getValue(), target.getClassType());
} catch (ConversionException ex) {
logger.debug("Could not convert target", ex);
errors.add(ex.getValidationMessage().withCategory(target.getName()));
} catch (IllegalStateException e) {
logger.debug("An error occured while getting validation message", e);
return setPropertiesAfterConversions(target, parameters);
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
@Vetoed
public class DefaultParametersControl implements ParametersControl {

private final Logger logger = LoggerFactory.getLogger(DefaultParametersControl.class);
private static final Logger logger = LoggerFactory.getLogger(DefaultParametersControl.class);
private final List<String> parameters = new ArrayList<>();
private final Pattern pattern;
private final String originalPattern;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void beforeRedirect() {
session.setAttribute(FLASH_INCLUDED_PARAMETERS, new HashMap<>(included));
} catch (IllegalStateException e) {
LOGGER.warn("HTTP Session was invalidated. It is not possible to include " +
"Result parameters on Flash Scope");
"Result parameters on Flash Scope", e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,13 @@ public void handle(@Observes VRaptorRequestStarted event) {
interceptorStack.start();
endRequestEvent.fire(new RequestSucceded(request, response));
} catch (ControllerNotFoundException e) {
LOGGER.debug("Could not found controller method", e);
controllerNotFoundHandler.couldntFind(event.getChain(), request, response);
} catch (MethodNotAllowedException e) {
LOGGER.debug(e.getMessage(), e);
LOGGER.debug("Method is not allowed", e);
methodNotAllowedHandler.deny(request, response, e.getAllowedMethods());
} catch (InvalidInputException e) {
LOGGER.debug(e.getMessage(), e);
LOGGER.debug("Invalid input", e);
invalidInputHandler.deny(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ protected String getValue(FileItem item, ServletRequest request) {
try {
return item.getString(encoding);
} catch (UnsupportedEncodingException e) {
logger.warn("Request have an invalid encoding. Ignoring it");
logger.debug("Request has an invalid encoding. Ignoring it", e);
}
}
return item.getString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

import javax.enterprise.inject.Vetoed;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* A Resource bundle that doesn't throw exception when there is no resource of given key.
* It only returns ??? + key + ??? when the key doesn't exist.
Expand All @@ -33,6 +36,7 @@
@Vetoed
public class SafeResourceBundle extends ResourceBundle {

private static final Logger logger = LoggerFactory.getLogger(SafeResourceBundle.class);
private final ResourceBundle delegate;
private final boolean isDefault;

Expand All @@ -59,6 +63,7 @@ protected Object handleGetObject(String key) {
try {
return delegate.getString(key);
} catch (MissingResourceException e) {
logger.warn("Resource missed while calling delegate", e);
return "???" + key + "???";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@
import br.com.caelum.vraptor.http.route.Router;
import br.com.caelum.vraptor.validator.Message;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@RequestScoped
public class DefaultRefererResult implements RefererResult {


private static final Logger logger = LoggerFactory.getLogger(DefaultRefererResult.class);

private final MutableRequest request;
private final Result result;
private final Router router;
Expand Down Expand Up @@ -73,6 +78,7 @@ public void forward() throws IllegalStateException {
ControllerMethod method = router.parse(referer, HttpMethod.GET, request);
executeMethod(method, result.use(logic()).forwardTo(method.getController().getType()));
} catch (ControllerNotFoundException | MethodNotAllowedException e) {
logger.warn("Could not find or doesn't allowed to get controller method", e);
result.use(page()).forwardTo(referer);
}
}
Expand All @@ -89,6 +95,7 @@ public void redirect() throws IllegalStateException {
ControllerMethod method = router.parse(referer, HttpMethod.GET, request);
executeMethod(method, result.use(logic()).redirectTo(method.getController().getType()));
} catch (ControllerNotFoundException | MethodNotAllowedException e) {
logger.warn("Could not find or doesn't allowed to get controller method", e);
result.use(page()).redirectTo(referer);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ private Class<?> createLinkToInterface(final Class<?> controller, String interfa
try {
return Class.forName(interfaceName);
} catch (ClassNotFoundException e1) {
logger.warn("Could not find class", e1);
// ok, continue
}

Expand Down

0 comments on commit 06ce603

Please sign in to comment.