Commit cb57091bd299bf6cf61c43f2c1abf88339b130f5
1 parent
f5c6bf55
Exists in
master
Correções de violações críticas de implementação apontadas pelo Sonar
Showing
7 changed files
with
22 additions
and
24 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/exception/ExceptionHandlerInterceptor.java
| @@ -49,7 +49,6 @@ import javax.interceptor.InvocationContext; | @@ -49,7 +49,6 @@ import javax.interceptor.InvocationContext; | ||
| 49 | import org.slf4j.Logger; | 49 | import org.slf4j.Logger; |
| 50 | 50 | ||
| 51 | import br.gov.frameworkdemoiselle.DemoiselleException; | 51 | import br.gov.frameworkdemoiselle.DemoiselleException; |
| 52 | -import br.gov.frameworkdemoiselle.exception.ExceptionHandler; | ||
| 53 | import br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap; | 52 | import br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap; |
| 54 | import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; | 53 | import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; |
| 55 | import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; | 54 | import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; |
| @@ -186,11 +185,10 @@ public class ExceptionHandlerInterceptor implements Serializable { | @@ -186,11 +185,10 @@ public class ExceptionHandlerInterceptor implements Serializable { | ||
| 186 | 185 | ||
| 187 | @AroundInvoke | 186 | @AroundInvoke |
| 188 | public Object manage(final InvocationContext ic) throws Exception { | 187 | public Object manage(final InvocationContext ic) throws Exception { |
| 189 | - Object target = null; | ||
| 190 | Object result = null; | 188 | Object result = null; |
| 189 | + Object target = ic.getTarget(); | ||
| 191 | 190 | ||
| 192 | try { | 191 | try { |
| 193 | - target = ic.getTarget(); | ||
| 194 | result = ic.proceed(); | 192 | result = ic.proceed(); |
| 195 | 193 | ||
| 196 | } catch (Exception cause) { | 194 | } catch (Exception cause) { |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AbstractLifecycleBootstrap.java
| @@ -131,7 +131,7 @@ public abstract class AbstractLifecycleBootstrap<A extends Annotation> implement | @@ -131,7 +131,7 @@ public abstract class AbstractLifecycleBootstrap<A extends Annotation> implement | ||
| 131 | getLogger().debug(getBundle().getString("executing-all", getAnnotationClass().getSimpleName())); | 131 | getLogger().debug(getBundle().getString("executing-all", getAnnotationClass().getSimpleName())); |
| 132 | 132 | ||
| 133 | Collections.sort(processors); | 133 | Collections.sort(processors); |
| 134 | - Throwable failure = null; | 134 | + Exception failure = null; |
| 135 | 135 | ||
| 136 | if (!registered) { | 136 | if (!registered) { |
| 137 | for (CustomContext tempContext : tempContexts) { | 137 | for (CustomContext tempContext : tempContexts) { |
| @@ -153,7 +153,7 @@ public abstract class AbstractLifecycleBootstrap<A extends Annotation> implement | @@ -153,7 +153,7 @@ public abstract class AbstractLifecycleBootstrap<A extends Annotation> implement | ||
| 153 | iter.remove(); | 153 | iter.remove(); |
| 154 | } | 154 | } |
| 155 | 155 | ||
| 156 | - } catch (Throwable cause) { | 156 | + } catch (Exception cause) { |
| 157 | failure = cause; | 157 | failure = cause; |
| 158 | } | 158 | } |
| 159 | } | 159 | } |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/AnnotatedMethodProcessor.java
| @@ -85,7 +85,7 @@ public class AnnotatedMethodProcessor<T> implements Comparable<AnnotatedMethodPr | @@ -85,7 +85,7 @@ public class AnnotatedMethodProcessor<T> implements Comparable<AnnotatedMethodPr | ||
| 85 | return orderThis.compareTo(orderOther); | 85 | return orderThis.compareTo(orderOther); |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | - public boolean process(Object... args) throws Throwable { | 88 | + public boolean process(Object... args) throws Exception { |
| 89 | getLogger().info(getBundle().getString("processing", getAnnotatedMethod().getJavaMember().toGenericString())); | 89 | getLogger().info(getBundle().getString("processing", getAnnotatedMethod().getJavaMember().toGenericString())); |
| 90 | 90 | ||
| 91 | try { | 91 | try { |
| @@ -98,11 +98,11 @@ public class AnnotatedMethodProcessor<T> implements Comparable<AnnotatedMethodPr | @@ -98,11 +98,11 @@ public class AnnotatedMethodProcessor<T> implements Comparable<AnnotatedMethodPr | ||
| 98 | return true; | 98 | return true; |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | - private void handleException(Throwable cause) throws Throwable { | 101 | + private void handleException(Throwable cause) throws Exception { |
| 102 | ApplicationException ann = cause.getClass().getAnnotation(ApplicationException.class); | 102 | ApplicationException ann = cause.getClass().getAnnotation(ApplicationException.class); |
| 103 | 103 | ||
| 104 | if (ann == null || SeverityType.FATAL == ann.severity()) { | 104 | if (ann == null || SeverityType.FATAL == ann.severity()) { |
| 105 | - throw cause; | 105 | + throw (cause instanceof Exception ? (Exception) cause : new Exception(cause)); |
| 106 | 106 | ||
| 107 | } else { | 107 | } else { |
| 108 | switch (ann.severity()) { | 108 | switch (ann.severity()) { |
impl/core/src/main/java/br/gov/frameworkdemoiselle/security/RequiredRoleInterceptor.java
| @@ -49,9 +49,6 @@ import org.slf4j.Logger; | @@ -49,9 +49,6 @@ import org.slf4j.Logger; | ||
| 49 | 49 | ||
| 50 | import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; | 50 | import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; |
| 51 | import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; | 51 | import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; |
| 52 | -import br.gov.frameworkdemoiselle.security.AuthorizationException; | ||
| 53 | -import br.gov.frameworkdemoiselle.security.RequiredRole; | ||
| 54 | -import br.gov.frameworkdemoiselle.security.SecurityContext; | ||
| 55 | import br.gov.frameworkdemoiselle.util.Beans; | 52 | import br.gov.frameworkdemoiselle.util.Beans; |
| 56 | import br.gov.frameworkdemoiselle.util.ResourceBundle; | 53 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
| 57 | 54 | ||
| @@ -90,7 +87,8 @@ public class RequiredRoleInterceptor implements Serializable { | @@ -90,7 +87,8 @@ public class RequiredRoleInterceptor implements Serializable { | ||
| 90 | 87 | ||
| 91 | if (getSecurityContext().isLoggedIn()) { | 88 | if (getSecurityContext().isLoggedIn()) { |
| 92 | getLogger().info( | 89 | getLogger().info( |
| 93 | - getBundle().getString("has-role-verification", getSecurityContext().getCurrentUser().getName(), roles)); | 90 | + getBundle().getString("has-role-verification", getSecurityContext().getCurrentUser().getName(), |
| 91 | + roles)); | ||
| 94 | } | 92 | } |
| 95 | 93 | ||
| 96 | List<String> userRoles = new ArrayList<String>(); | 94 | List<String> userRoles = new ArrayList<String>(); |
| @@ -102,15 +100,16 @@ public class RequiredRoleInterceptor implements Serializable { | @@ -102,15 +100,16 @@ public class RequiredRoleInterceptor implements Serializable { | ||
| 102 | } | 100 | } |
| 103 | 101 | ||
| 104 | if (userRoles.isEmpty()) { | 102 | if (userRoles.isEmpty()) { |
| 105 | - getLogger().error( | ||
| 106 | - getBundle().getString("does-not-have-role", getSecurityContext().getCurrentUser().getName(), roles)); | 103 | + getLogger() |
| 104 | + .error(getBundle().getString("does-not-have-role", getSecurityContext().getCurrentUser().getName(), | ||
| 105 | + roles)); | ||
| 107 | 106 | ||
| 108 | - @SuppressWarnings("unused") | ||
| 109 | - AuthorizationException a = new AuthorizationException(null); | 107 | + // AuthorizationException a = new AuthorizationException(null); |
| 110 | throw new AuthorizationException(getBundle().getString("does-not-have-role-ui", roles)); | 108 | throw new AuthorizationException(getBundle().getString("does-not-have-role-ui", roles)); |
| 111 | } | 109 | } |
| 112 | 110 | ||
| 113 | - getLogger().debug(getBundle().getString("user-has-role", getSecurityContext().getCurrentUser().getName(), userRoles)); | 111 | + getLogger().debug( |
| 112 | + getBundle().getString("user-has-role", getSecurityContext().getCurrentUser().getName(), userRoles)); | ||
| 114 | 113 | ||
| 115 | return ic.proceed(); | 114 | return ic.proceed(); |
| 116 | } | 115 | } |
impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/internal/producer/DataSourceProducer.java
| @@ -48,8 +48,8 @@ public class DataSourceProducer implements Serializable { | @@ -48,8 +48,8 @@ public class DataSourceProducer implements Serializable { | ||
| 48 | 48 | ||
| 49 | try { | 49 | try { |
| 50 | create(dataBaseName); | 50 | create(dataBaseName); |
| 51 | - } catch (Throwable t) { | ||
| 52 | - throw new DemoiselleException(t); | 51 | + } catch (Exception cause) { |
| 52 | + throw new DemoiselleException(cause); | ||
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | logger.debug(bundle.getString("datasource-name-found", dataBaseName)); | 55 | logger.debug(bundle.getString("datasource-name-found", dataBaseName)); |
impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/internal/producer/EntityManagerFactoryProducer.java
| @@ -113,8 +113,8 @@ public class EntityManagerFactoryProducer implements Serializable { | @@ -113,8 +113,8 @@ public class EntityManagerFactoryProducer implements Serializable { | ||
| 113 | 113 | ||
| 114 | try { | 114 | try { |
| 115 | create(persistenceUnit); | 115 | create(persistenceUnit); |
| 116 | - } catch (Throwable t) { | ||
| 117 | - throw new DemoiselleException(t); | 116 | + } catch (Exception cause) { |
| 117 | + throw new DemoiselleException(cause); | ||
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | logger.debug(bundle.getString("persistence-unit-name-found", persistenceUnit)); | 120 | logger.debug(bundle.getString("persistence-unit-name-found", persistenceUnit)); |
impl/extension/jsf/src/main/java/br/gov/frameworkdemoiselle/util/Redirector.java
| @@ -42,6 +42,7 @@ import java.util.ArrayList; | @@ -42,6 +42,7 @@ import java.util.ArrayList; | ||
| 42 | import java.util.HashMap; | 42 | import java.util.HashMap; |
| 43 | import java.util.List; | 43 | import java.util.List; |
| 44 | import java.util.Map; | 44 | import java.util.Map; |
| 45 | +import java.util.Map.Entry; | ||
| 45 | 46 | ||
| 46 | import javax.faces.FacesException; | 47 | import javax.faces.FacesException; |
| 47 | import javax.faces.application.ViewHandler; | 48 | import javax.faces.application.ViewHandler; |
| @@ -81,10 +82,10 @@ public class Redirector implements Serializable { | @@ -81,10 +82,10 @@ public class Redirector implements Serializable { | ||
| 81 | ArrayList<String> list; | 82 | ArrayList<String> list; |
| 82 | result = new HashMap<String, List<String>>(); | 83 | result = new HashMap<String, List<String>>(); |
| 83 | 84 | ||
| 84 | - for (String key : map.keySet()) { | 85 | + for (Entry<String, Object> entry : map.entrySet()) { |
| 85 | list = new ArrayList<String>(); | 86 | list = new ArrayList<String>(); |
| 86 | - list.add(map.get(key).toString()); | ||
| 87 | - result.put(key, list); | 87 | + list.add(entry.getValue().toString()); |
| 88 | + result.put(entry.getKey(), list); | ||
| 88 | } | 89 | } |
| 89 | } | 90 | } |
| 90 | 91 |