Browse Source

Avoid unnecessary boxing where primitives can be used

Closes gh-23267
pull/23279/head
Сергей Цыпанов 7 years ago committed by Sam Brannen
parent
commit
1728bf17fc
  1. 2
      spring-aop/src/main/java/org/springframework/aop/config/ScopedProxyBeanDefinitionDecorator.java
  2. 2
      spring-beans/src/main/java/org/springframework/beans/factory/annotation/RequiredAnnotationBeanPostProcessor.java
  3. 6
      spring-context/src/main/java/org/springframework/cache/config/CacheAdviceParser.java
  4. 4
      spring-context/src/main/java/org/springframework/context/annotation/ComponentScanBeanDefinitionParser.java
  5. 2
      spring-context/src/main/java/org/springframework/scheduling/config/AnnotationDrivenBeanDefinitionParser.java
  6. 4
      spring-context/src/main/java/org/springframework/scheduling/config/TaskExecutorFactoryBean.java
  7. 6
      spring-context/src/main/java/org/springframework/scheduling/support/CronSequenceGenerator.java
  8. 2
      spring-context/src/main/java/org/springframework/scripting/support/ScriptFactoryPostProcessor.java
  9. 2
      spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaderAccessor.java
  10. 2
      spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaders.java
  11. 2
      spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceUnitReader.java
  12. 2
      spring-tx/src/main/java/org/springframework/transaction/config/TxAdviceBeanDefinitionParser.java
  13. 2
      spring-web/src/main/java/org/springframework/http/codec/ServerSentEventHttpMessageReader.java
  14. 2
      spring-webmvc/src/main/java/org/springframework/web/servlet/config/AnnotationDrivenBeanDefinitionParser.java
  15. 2
      spring-websocket/src/main/java/org/springframework/web/socket/config/HandlersBeanDefinitionParser.java
  16. 4
      spring-websocket/src/main/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParser.java
  17. 2
      spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/AbstractClientSockJsSession.java

2
spring-aop/src/main/java/org/springframework/aop/config/ScopedProxyBeanDefinitionDecorator.java

@ -45,7 +45,7 @@ class ScopedProxyBeanDefinitionDecorator implements BeanDefinitionDecorator {
if (node instanceof Element) { if (node instanceof Element) {
Element ele = (Element) node; Element ele = (Element) node;
if (ele.hasAttribute(PROXY_TARGET_CLASS)) { if (ele.hasAttribute(PROXY_TARGET_CLASS)) {
proxyTargetClass = Boolean.valueOf(ele.getAttribute(PROXY_TARGET_CLASS)); proxyTargetClass = Boolean.parseBoolean(ele.getAttribute(PROXY_TARGET_CLASS));
} }
} }

2
spring-beans/src/main/java/org/springframework/beans/factory/annotation/RequiredAnnotationBeanPostProcessor.java

@ -183,7 +183,7 @@ public class RequiredAnnotationBeanPostProcessor extends InstantiationAwareBeanP
return true; return true;
} }
Object value = beanDefinition.getAttribute(SKIP_REQUIRED_CHECK_ATTRIBUTE); Object value = beanDefinition.getAttribute(SKIP_REQUIRED_CHECK_ATTRIBUTE);
return (value != null && (Boolean.TRUE.equals(value) || Boolean.valueOf(value.toString()))); return (value != null && (Boolean.TRUE.equals(value) || Boolean.parseBoolean(value.toString())));
} }
/** /**

6
spring-context/src/main/java/org/springframework/cache/config/CacheAdviceParser.java vendored

@ -111,7 +111,7 @@ class CacheAdviceParser extends AbstractSingleBeanDefinitionParser {
CacheableOperation.Builder builder = prop.merge(opElement, CacheableOperation.Builder builder = prop.merge(opElement,
parserContext.getReaderContext(), new CacheableOperation.Builder()); parserContext.getReaderContext(), new CacheableOperation.Builder());
builder.setUnless(getAttributeValue(opElement, "unless", "")); builder.setUnless(getAttributeValue(opElement, "unless", ""));
builder.setSync(Boolean.valueOf(getAttributeValue(opElement, "sync", "false"))); builder.setSync(Boolean.parseBoolean(getAttributeValue(opElement, "sync", "false")));
Collection<CacheOperation> col = cacheOpMap.get(nameHolder); Collection<CacheOperation> col = cacheOpMap.get(nameHolder);
if (col == null) { if (col == null) {
@ -132,12 +132,12 @@ class CacheAdviceParser extends AbstractSingleBeanDefinitionParser {
String wide = opElement.getAttribute("all-entries"); String wide = opElement.getAttribute("all-entries");
if (StringUtils.hasText(wide)) { if (StringUtils.hasText(wide)) {
builder.setCacheWide(Boolean.valueOf(wide.trim())); builder.setCacheWide(Boolean.parseBoolean(wide.trim()));
} }
String after = opElement.getAttribute("before-invocation"); String after = opElement.getAttribute("before-invocation");
if (StringUtils.hasText(after)) { if (StringUtils.hasText(after)) {
builder.setBeforeInvocation(Boolean.valueOf(after.trim())); builder.setBeforeInvocation(Boolean.parseBoolean(after.trim()));
} }
Collection<CacheOperation> col = cacheOpMap.get(nameHolder); Collection<CacheOperation> col = cacheOpMap.get(nameHolder);

4
spring-context/src/main/java/org/springframework/context/annotation/ComponentScanBeanDefinitionParser.java

@ -96,7 +96,7 @@ public class ComponentScanBeanDefinitionParser implements BeanDefinitionParser {
protected ClassPathBeanDefinitionScanner configureScanner(ParserContext parserContext, Element element) { protected ClassPathBeanDefinitionScanner configureScanner(ParserContext parserContext, Element element) {
boolean useDefaultFilters = true; boolean useDefaultFilters = true;
if (element.hasAttribute(USE_DEFAULT_FILTERS_ATTRIBUTE)) { if (element.hasAttribute(USE_DEFAULT_FILTERS_ATTRIBUTE)) {
useDefaultFilters = Boolean.valueOf(element.getAttribute(USE_DEFAULT_FILTERS_ATTRIBUTE)); useDefaultFilters = Boolean.parseBoolean(element.getAttribute(USE_DEFAULT_FILTERS_ATTRIBUTE));
} }
// Delegate bean definition registration to scanner class. // Delegate bean definition registration to scanner class.
@ -145,7 +145,7 @@ public class ComponentScanBeanDefinitionParser implements BeanDefinitionParser {
// Register annotation config processors, if necessary. // Register annotation config processors, if necessary.
boolean annotationConfig = true; boolean annotationConfig = true;
if (element.hasAttribute(ANNOTATION_CONFIG_ATTRIBUTE)) { if (element.hasAttribute(ANNOTATION_CONFIG_ATTRIBUTE)) {
annotationConfig = Boolean.valueOf(element.getAttribute(ANNOTATION_CONFIG_ATTRIBUTE)); annotationConfig = Boolean.parseBoolean(element.getAttribute(ANNOTATION_CONFIG_ATTRIBUTE));
} }
if (annotationConfig) { if (annotationConfig) {
Set<BeanDefinitionHolder> processorDefinitions = Set<BeanDefinitionHolder> processorDefinitions =

2
spring-context/src/main/java/org/springframework/scheduling/config/AnnotationDrivenBeanDefinitionParser.java

@ -81,7 +81,7 @@ public class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParse
if (StringUtils.hasText(exceptionHandler)) { if (StringUtils.hasText(exceptionHandler)) {
builder.addPropertyReference("exceptionHandler", exceptionHandler); builder.addPropertyReference("exceptionHandler", exceptionHandler);
} }
if (Boolean.valueOf(element.getAttribute(AopNamespaceUtils.PROXY_TARGET_CLASS_ATTRIBUTE))) { if (Boolean.parseBoolean(element.getAttribute(AopNamespaceUtils.PROXY_TARGET_CLASS_ATTRIBUTE))) {
builder.addPropertyValue("proxyTargetClass", true); builder.addPropertyValue("proxyTargetClass", true);
} }
registerPostProcessor(parserContext, builder, TaskManagementConfigUtils.ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME); registerPostProcessor(parserContext, builder, TaskManagementConfigUtils.ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME);

4
spring-context/src/main/java/org/springframework/scheduling/config/TaskExecutorFactoryBean.java

@ -106,8 +106,8 @@ public class TaskExecutorFactoryBean implements
int maxPoolSize; int maxPoolSize;
int separatorIndex = this.poolSize.indexOf('-'); int separatorIndex = this.poolSize.indexOf('-');
if (separatorIndex != -1) { if (separatorIndex != -1) {
corePoolSize = Integer.valueOf(this.poolSize.substring(0, separatorIndex)); corePoolSize = Integer.parseInt(this.poolSize.substring(0, separatorIndex));
maxPoolSize = Integer.valueOf(this.poolSize.substring(separatorIndex + 1, this.poolSize.length())); maxPoolSize = Integer.parseInt(this.poolSize.substring(separatorIndex + 1, this.poolSize.length()));
if (corePoolSize > maxPoolSize) { if (corePoolSize > maxPoolSize) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Lower bound of pool-size range must not exceed the upper bound"); "Lower bound of pool-size range must not exceed the upper bound");

6
spring-context/src/main/java/org/springframework/scheduling/support/CronSequenceGenerator.java

@ -372,7 +372,7 @@ public class CronSequenceGenerator {
return result; return result;
} }
if (!field.contains("-")) { if (!field.contains("-")) {
result[0] = result[1] = Integer.valueOf(field); result[0] = result[1] = Integer.parseInt(field);
} }
else { else {
String[] split = StringUtils.delimitedListToStringArray(field, "-"); String[] split = StringUtils.delimitedListToStringArray(field, "-");
@ -380,8 +380,8 @@ public class CronSequenceGenerator {
throw new IllegalArgumentException("Range has more than two fields: '" + throw new IllegalArgumentException("Range has more than two fields: '" +
field + "' in expression \"" + this.expression + "\""); field + "' in expression \"" + this.expression + "\"");
} }
result[0] = Integer.valueOf(split[0]); result[0] = Integer.parseInt(split[0]);
result[1] = Integer.valueOf(split[1]); result[1] = Integer.parseInt(split[1]);
} }
if (result[0] >= max || result[1] >= max) { if (result[0] >= max || result[1] >= max) {
throw new IllegalArgumentException("Range exceeds maximum (" + max + "): '" + throw new IllegalArgumentException("Range exceeds maximum (" + max + "): '" +

2
spring-context/src/main/java/org/springframework/scripting/support/ScriptFactoryPostProcessor.java

@ -426,7 +426,7 @@ public class ScriptFactoryPostProcessor extends InstantiationAwareBeanPostProces
proxyTargetClass = (Boolean) attributeValue; proxyTargetClass = (Boolean) attributeValue;
} }
else if (attributeValue instanceof String) { else if (attributeValue instanceof String) {
proxyTargetClass = Boolean.valueOf((String) attributeValue); proxyTargetClass = Boolean.parseBoolean((String) attributeValue);
} }
else if (attributeValue != null) { else if (attributeValue != null) {
throw new BeanDefinitionStoreException("Invalid proxy target class attribute [" + throw new BeanDefinitionStoreException("Invalid proxy target class attribute [" +

2
spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaderAccessor.java

@ -243,7 +243,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor {
if (rawValues == null) { if (rawValues == null) {
return Arrays.copyOf(DEFAULT_HEARTBEAT, 2); return Arrays.copyOf(DEFAULT_HEARTBEAT, 2);
} }
return new long[] {Long.valueOf(rawValues[0]), Long.valueOf(rawValues[1])}; return new long[] {Long.parseLong(rawValues[0]), Long.parseLong(rawValues[1])};
} }
public void setAcceptVersion(String acceptVersion) { public void setAcceptVersion(String acceptVersion) {

2
spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaders.java

@ -282,7 +282,7 @@ public class StompHeaders implements MultiValueMap<String, String>, Serializable
if (rawValues == null) { if (rawValues == null) {
return null; return null;
} }
return new long[] {Long.valueOf(rawValues[0]), Long.valueOf(rawValues[1])}; return new long[] {Long.parseLong(rawValues[0]), Long.parseLong(rawValues[1])};
} }
/** /**

2
spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceUnitReader.java

@ -230,7 +230,7 @@ final class PersistenceUnitReader {
Element excludeUnlistedClasses = DomUtils.getChildElementByTagName(persistenceUnit, EXCLUDE_UNLISTED_CLASSES); Element excludeUnlistedClasses = DomUtils.getChildElementByTagName(persistenceUnit, EXCLUDE_UNLISTED_CLASSES);
if (excludeUnlistedClasses != null) { if (excludeUnlistedClasses != null) {
String excludeText = DomUtils.getTextValue(excludeUnlistedClasses); String excludeText = DomUtils.getTextValue(excludeUnlistedClasses);
unitInfo.setExcludeUnlistedClasses(!StringUtils.hasText(excludeText) || Boolean.valueOf(excludeText)); unitInfo.setExcludeUnlistedClasses(!StringUtils.hasText(excludeText) || Boolean.parseBoolean(excludeText));
} }
// set JPA 2.0 shared cache mode // set JPA 2.0 shared cache mode

2
spring-tx/src/main/java/org/springframework/transaction/config/TxAdviceBeanDefinitionParser.java

@ -124,7 +124,7 @@ class TxAdviceBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
} }
} }
if (StringUtils.hasText(readOnly)) { if (StringUtils.hasText(readOnly)) {
attribute.setReadOnly(Boolean.valueOf(methodEle.getAttribute(READ_ONLY_ATTRIBUTE))); attribute.setReadOnly(Boolean.parseBoolean(methodEle.getAttribute(READ_ONLY_ATTRIBUTE)));
} }
List<RollbackRuleAttribute> rollbackRules = new LinkedList<>(); List<RollbackRuleAttribute> rollbackRules = new LinkedList<>();

2
spring-web/src/main/java/org/springframework/http/codec/ServerSentEventHttpMessageReader.java

@ -130,7 +130,7 @@ public class ServerSentEventHttpMessageReader implements HttpMessageReader<Objec
sseBuilder.event(line.substring(6).trim()); sseBuilder.event(line.substring(6).trim());
} }
else if (line.startsWith("retry:")) { else if (line.startsWith("retry:")) {
sseBuilder.retry(Duration.ofMillis(Long.valueOf(line.substring(6).trim()))); sseBuilder.retry(Duration.ofMillis(Long.parseLong(line.substring(6).trim())));
} }
else if (line.startsWith(":")) { else if (line.startsWith(":")) {
comment = (comment != null ? comment : new StringBuilder()); comment = (comment != null ? comment : new StringBuilder());

2
spring-webmvc/src/main/java/org/springframework/web/servlet/config/AnnotationDrivenBeanDefinitionParser.java

@ -569,7 +569,7 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser {
} }
} }
if (convertersElement == null || Boolean.valueOf(convertersElement.getAttribute("register-defaults"))) { if (convertersElement == null || Boolean.parseBoolean(convertersElement.getAttribute("register-defaults"))) {
messageConverters.setSource(source); messageConverters.setSource(source);
messageConverters.add(createConverterDefinition(ByteArrayHttpMessageConverter.class, source)); messageConverters.add(createConverterDefinition(ByteArrayHttpMessageConverter.class, source));

2
spring-websocket/src/main/java/org/springframework/web/socket/config/HandlersBeanDefinitionParser.java

@ -64,7 +64,7 @@ class HandlersBeanDefinitionParser implements BeanDefinitionParser {
context.pushContainingComponent(compDefinition); context.pushContainingComponent(compDefinition);
String orderAttribute = element.getAttribute("order"); String orderAttribute = element.getAttribute("order");
int order = orderAttribute.isEmpty() ? DEFAULT_MAPPING_ORDER : Integer.valueOf(orderAttribute); int order = orderAttribute.isEmpty() ? DEFAULT_MAPPING_ORDER : Integer.parseInt(orderAttribute);
RootBeanDefinition handlerMappingDef = new RootBeanDefinition(WebSocketHandlerMapping.class); RootBeanDefinition handlerMappingDef = new RootBeanDefinition(WebSocketHandlerMapping.class);
handlerMappingDef.setSource(source); handlerMappingDef.setSource(source);

4
spring-websocket/src/main/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParser.java

@ -200,7 +200,7 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
RootBeanDefinition handlerMappingDef = new RootBeanDefinition(WebSocketHandlerMapping.class); RootBeanDefinition handlerMappingDef = new RootBeanDefinition(WebSocketHandlerMapping.class);
String orderAttribute = element.getAttribute("order"); String orderAttribute = element.getAttribute("order");
int order = orderAttribute.isEmpty() ? DEFAULT_MAPPING_ORDER : Integer.valueOf(orderAttribute); int order = orderAttribute.isEmpty() ? DEFAULT_MAPPING_ORDER : Integer.parseInt(orderAttribute);
handlerMappingDef.getPropertyValues().add("order", order); handlerMappingDef.getPropertyValues().add("order", order);
String pathHelper = element.getAttribute("path-helper"); String pathHelper = element.getAttribute("path-helper");
@ -485,7 +485,7 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
converters.add(object); converters.add(object);
} }
} }
if (convertersElement == null || Boolean.valueOf(convertersElement.getAttribute("register-defaults"))) { if (convertersElement == null || Boolean.parseBoolean(convertersElement.getAttribute("register-defaults"))) {
converters.setSource(source); converters.setSource(source);
converters.add(new RootBeanDefinition(StringMessageConverter.class)); converters.add(new RootBeanDefinition(StringMessageConverter.class));
converters.add(new RootBeanDefinition(ByteArrayMessageConverter.class)); converters.add(new RootBeanDefinition(ByteArrayMessageConverter.class));

2
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/AbstractClientSockJsSession.java

@ -307,7 +307,7 @@ public abstract class AbstractClientSockJsSession implements WebSocketSession {
if (frameData != null) { if (frameData != null) {
String[] data = getMessageCodec().decode(frameData); String[] data = getMessageCodec().decode(frameData);
if (data != null && data.length == 2) { if (data != null && data.length == 2) {
closeStatus = new CloseStatus(Integer.valueOf(data[0]), data[1]); closeStatus = new CloseStatus(Integer.parseInt(data[0]), data[1]);
} }
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("Processing SockJS close frame with " + closeStatus + " in " + this); logger.debug("Processing SockJS close frame with " + closeStatus + " in " + this);

Loading…
Cancel
Save