Avoid defensive checks against Java 8 API (java.util.Optional etc)

This commit also fixes broken javadoc links and code references.

Issue: SPR-13188
This commit is contained in:
Juergen Hoeller
2016-07-05 02:08:59 +02:00
parent adb935db79
commit 51252ebbca
98 changed files with 290 additions and 1232 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -52,7 +52,7 @@ public class CachingConfigurationSelector extends AdviceModeImportSelector<Enabl
private static final boolean jsr107Present = ClassUtils.isPresent(
"javax.cache.Cache", CachingConfigurationSelector.class.getClassLoader());
private static final boolean jCacheImplPresent = ClassUtils.isPresent(
private static final boolean jcacheImplPresent = ClassUtils.isPresent(
PROXY_JCACHE_CONFIGURATION_CLASS, CachingConfigurationSelector.class.getClassLoader());
@@ -81,7 +81,7 @@ public class CachingConfigurationSelector extends AdviceModeImportSelector<Enabl
List<String> result = new ArrayList<String>();
result.add(AutoProxyRegistrar.class.getName());
result.add(ProxyCachingConfiguration.class.getName());
if (jsr107Present && jCacheImplPresent) {
if (jsr107Present && jcacheImplPresent) {
result.add(PROXY_JCACHE_CONFIGURATION_CLASS);
}
return result.toArray(new String[result.size()]);
@@ -94,7 +94,7 @@ public class CachingConfigurationSelector extends AdviceModeImportSelector<Enabl
private String[] getAspectJImports() {
List<String> result = new ArrayList<String>();
result.add(CACHE_ASPECT_CONFIGURATION_CLASS_NAME);
if (jsr107Present && jCacheImplPresent) {
if (jsr107Present && jcacheImplPresent) {
result.add(JCACHE_ASPECT_CONFIGURATION_CLASS_NAME);
}
return result.toArray(new String[result.size()]);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -60,11 +60,10 @@ class AnnotationDrivenCacheBeanDefinitionParser implements BeanDefinitionParser
private static final String JCACHE_ASPECT_CLASS_NAME =
"org.springframework.cache.aspectj.JCacheCacheAspect";
private static final boolean jsr107Present = ClassUtils.isPresent(
"javax.cache.Cache", AnnotationDrivenCacheBeanDefinitionParser.class.getClassLoader());
private static final boolean jCacheImplPresent = ClassUtils.isPresent(
private static final boolean jcacheImplPresent = ClassUtils.isPresent(
"org.springframework.cache.jcache.interceptor.DefaultJCacheOperationSource",
AnnotationDrivenCacheBeanDefinitionParser.class.getClassLoader());
@@ -91,7 +90,7 @@ class AnnotationDrivenCacheBeanDefinitionParser implements BeanDefinitionParser
private void registerCacheAspect(Element element, ParserContext parserContext) {
SpringCachingConfigurer.registerCacheAspect(element, parserContext);
if (jsr107Present && jCacheImplPresent) { // Register JCache aspect
if (jsr107Present && jcacheImplPresent) {
JCacheCachingConfigurer.registerCacheAspect(element, parserContext);
}
}
@@ -99,7 +98,7 @@ class AnnotationDrivenCacheBeanDefinitionParser implements BeanDefinitionParser
private void registerCacheAdvisor(Element element, ParserContext parserContext) {
AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(parserContext, element);
SpringCachingConfigurer.registerCacheAdvisor(element, parserContext);
if (jsr107Present && jCacheImplPresent) { // Register JCache advisor
if (jsr107Present && jcacheImplPresent) {
JCacheCachingConfigurer.registerCacheAdvisor(element, parserContext);
}
}

View File

@@ -43,7 +43,6 @@ import org.springframework.cache.CacheManager;
import org.springframework.context.ApplicationContext;
import org.springframework.context.expression.AnnotatedElementKey;
import org.springframework.expression.EvaluationContext;
import org.springframework.lang.UsesJava8;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
@@ -81,18 +80,6 @@ import org.springframework.util.StringUtils;
public abstract class CacheAspectSupport extends AbstractCacheInvoker
implements BeanFactoryAware, InitializingBean, SmartInitializingSingleton {
private static Class<?> javaUtilOptionalClass = null;
static {
try {
javaUtilOptionalClass =
ClassUtils.forName("java.util.Optional", CacheAspectSupport.class.getClassLoader());
}
catch (ClassNotFoundException ex) {
// Java 8 not available - Optional references simply not supported then.
}
}
protected final Log logger = LogFactory.getLog(getClass());
private final Map<CacheOperationCacheKey, CacheOperationMetadata> metadataCache =
@@ -401,9 +388,9 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
if (cacheHit != null && cachePutRequests.isEmpty() && !hasCachePut(contexts)) {
// If there are no put requests, just use the cache hit
cacheValue = cacheHit.get();
if (method.getReturnType() == javaUtilOptionalClass &&
(cacheValue == null || cacheValue.getClass() != javaUtilOptionalClass)) {
returnValue = OptionalUnwrapper.wrap(cacheValue);
if (method.getReturnType() == Optional.class &&
(cacheValue == null || cacheValue.getClass() != Optional.class)) {
returnValue = Optional.ofNullable(cacheValue);
}
else {
returnValue = cacheValue;
@@ -412,12 +399,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
else {
// Invoke the method if we don't have a cache hit
returnValue = invokeOperation(invoker);
if (returnValue != null && returnValue.getClass() == javaUtilOptionalClass) {
cacheValue = OptionalUnwrapper.unwrap(returnValue);
}
else {
cacheValue = returnValue;
}
cacheValue = ObjectUtils.unwrapOptional(returnValue);
}
// Collect any explicit @CachePuts
@@ -828,26 +810,4 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
}
}
/**
* Inner class to avoid a hard dependency on Java 8.
*/
@UsesJava8
private static class OptionalUnwrapper {
public static Object unwrap(Object optionalObject) {
Optional<?> optional = (Optional<?>) optionalObject;
if (!optional.isPresent()) {
return null;
}
Object result = optional.get();
Assert.isTrue(!(result instanceof Optional), "Multi-level Optional usage not supported");
return result;
}
public static Object wrap(Object value) {
return Optional.ofNullable(value);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@ import java.util.concurrent.ConcurrentHashMap;
import org.springframework.core.DecoratingClassLoader;
import org.springframework.core.OverridingClassLoader;
import org.springframework.core.SmartClassLoader;
import org.springframework.lang.UsesJava7;
import org.springframework.util.ReflectionUtils;
/**
@@ -37,13 +36,10 @@ import org.springframework.util.ReflectionUtils;
* @see AbstractApplicationContext
* @see org.springframework.beans.factory.config.ConfigurableBeanFactory#setTempClassLoader
*/
@UsesJava7
class ContextTypeMatchClassLoader extends DecoratingClassLoader implements SmartClassLoader {
static {
if (parallelCapableClassLoaderAvailable) {
ClassLoader.registerAsParallelCapable();
}
ClassLoader.registerAsParallelCapable();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,7 +24,6 @@ import java.util.TimeZone;
import org.springframework.context.i18n.LocaleContext;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.context.i18n.TimeZoneAwareLocaleContext;
import org.springframework.lang.UsesJava8;
/**
* A context that holds user-specific <code>java.time</code> (JSR-310) settings
@@ -35,7 +34,6 @@ import org.springframework.lang.UsesJava8;
* @since 4.0
* @see DateTimeContextHolder
*/
@UsesJava8
public class DateTimeContext {
private Chronology chronology;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@ import java.time.format.DateTimeFormatter;
import java.util.Locale;
import org.springframework.core.NamedThreadLocal;
import org.springframework.lang.UsesJava8;
/**
* A holder for a thread-local user {@link DateTimeContext}.
@@ -28,7 +27,6 @@ import org.springframework.lang.UsesJava8;
* @author Juergen Hoeller
* @since 4.0
*/
@UsesJava8
public final class DateTimeContextHolder {
private static final ThreadLocal<DateTimeContext> dateTimeContextHolder =

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,7 +29,6 @@ import java.util.GregorianCalendar;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.converter.ConverterRegistry;
import org.springframework.format.datetime.DateFormatterRegistrar;
import org.springframework.lang.UsesJava8;
/**
* Installs lower-level type converters required to integrate
@@ -43,7 +42,6 @@ import org.springframework.lang.UsesJava8;
* @author Juergen Hoeller
* @since 4.0.1
*/
@UsesJava8
final class DateTimeConverters {
/**
@@ -86,7 +84,6 @@ final class DateTimeConverters {
}
@UsesJava8
private static class LocalDateTimeToLocalDateConverter implements Converter<LocalDateTime, LocalDate> {
@Override
@@ -96,7 +93,6 @@ final class DateTimeConverters {
}
@UsesJava8
private static class LocalDateTimeToLocalTimeConverter implements Converter<LocalDateTime, LocalTime> {
@Override
@@ -106,7 +102,6 @@ final class DateTimeConverters {
}
@UsesJava8
private static class ZonedDateTimeToLocalDateConverter implements Converter<ZonedDateTime, LocalDate> {
@Override
@@ -116,7 +111,6 @@ final class DateTimeConverters {
}
@UsesJava8
private static class ZonedDateTimeToLocalTimeConverter implements Converter<ZonedDateTime, LocalTime> {
@Override
@@ -126,7 +120,6 @@ final class DateTimeConverters {
}
@UsesJava8
private static class ZonedDateTimeToLocalDateTimeConverter implements Converter<ZonedDateTime, LocalDateTime> {
@Override
@@ -135,7 +128,6 @@ final class DateTimeConverters {
}
}
@UsesJava8
private static class ZonedDateTimeToOffsetDateTimeConverter implements Converter<ZonedDateTime, OffsetDateTime> {
@Override
@@ -145,7 +137,6 @@ final class DateTimeConverters {
}
@UsesJava8
private static class ZonedDateTimeToInstantConverter implements Converter<ZonedDateTime, Instant> {
@Override
@@ -156,7 +147,6 @@ final class DateTimeConverters {
}
@UsesJava8
private static class OffsetDateTimeToLocalDateConverter implements Converter<OffsetDateTime, LocalDate> {
@Override
@@ -166,7 +156,6 @@ final class DateTimeConverters {
}
@UsesJava8
private static class OffsetDateTimeToLocalTimeConverter implements Converter<OffsetDateTime, LocalTime> {
@Override
@@ -176,7 +165,6 @@ final class DateTimeConverters {
}
@UsesJava8
private static class OffsetDateTimeToLocalDateTimeConverter implements Converter<OffsetDateTime, LocalDateTime> {
@Override
@@ -186,7 +174,6 @@ final class DateTimeConverters {
}
@UsesJava8
private static class OffsetDateTimeToZonedDateTimeConverter implements Converter<OffsetDateTime, ZonedDateTime> {
@Override
@@ -196,7 +183,6 @@ final class DateTimeConverters {
}
@UsesJava8
private static class OffsetDateTimeToInstantConverter implements Converter<OffsetDateTime, Instant> {
@Override
@@ -206,7 +192,6 @@ final class DateTimeConverters {
}
@UsesJava8
private static class CalendarToZonedDateTimeConverter implements Converter<Calendar, ZonedDateTime> {
@Override
@@ -216,7 +201,6 @@ final class DateTimeConverters {
}
@UsesJava8
private static class CalendarToOffsetDateTimeConverter implements Converter<Calendar, OffsetDateTime> {
@Override
@@ -226,7 +210,6 @@ final class DateTimeConverters {
}
@UsesJava8
private static class CalendarToLocalDateConverter implements Converter<Calendar, LocalDate> {
@Override
@@ -236,7 +219,6 @@ final class DateTimeConverters {
}
@UsesJava8
private static class CalendarToLocalTimeConverter implements Converter<Calendar, LocalTime> {
@Override
@@ -246,7 +228,6 @@ final class DateTimeConverters {
}
@UsesJava8
private static class CalendarToLocalDateTimeConverter implements Converter<Calendar, LocalDateTime> {
@Override
@@ -256,7 +237,6 @@ final class DateTimeConverters {
}
@UsesJava8
private static class CalendarToInstantConverter implements Converter<Calendar, Instant> {
@Override
@@ -267,7 +247,6 @@ final class DateTimeConverters {
}
@UsesJava8
private static class LongToInstantConverter implements Converter<Long, Instant> {
@Override
@@ -277,7 +256,6 @@ final class DateTimeConverters {
}
@UsesJava8
private static class InstantToLongConverter implements Converter<Instant, Long> {
@Override

View File

@@ -22,7 +22,6 @@ import java.time.format.ResolverStyle;
import java.util.TimeZone;
import org.springframework.format.annotation.DateTimeFormat.ISO;
import org.springframework.lang.UsesJava8;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -44,7 +43,6 @@ import org.springframework.util.StringUtils;
* @see #setDateTimeStyle
* @see DateTimeFormatterFactoryBean
*/
@UsesJava8
public class DateTimeFormatterFactory {
private String pattern;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,7 +35,6 @@ import java.util.Map;
import org.springframework.format.FormatterRegistrar;
import org.springframework.format.FormatterRegistry;
import org.springframework.format.annotation.DateTimeFormat.ISO;
import org.springframework.lang.UsesJava8;
/**
* Configures the JSR-310 <code>java.time</code> formatting system for use with Spring.
@@ -51,7 +50,6 @@ import org.springframework.lang.UsesJava8;
* @see org.springframework.format.datetime.DateFormatterRegistrar
* @see org.springframework.format.datetime.joda.DateTimeFormatterFactoryBean
*/
@UsesJava8
public class DateTimeFormatterRegistrar implements FormatterRegistrar {
private enum Type {DATE, TIME, DATE_TIME}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@ import java.time.Duration;
import java.util.Locale;
import org.springframework.format.Formatter;
import org.springframework.lang.UsesJava8;
/**
* {@link Formatter} implementation for a JSR-310 {@link Duration},
@@ -31,7 +30,6 @@ import org.springframework.lang.UsesJava8;
* @since 4.2.4
* @see Duration#parse
*/
@UsesJava8
class DurationFormatter implements Formatter<Duration> {
@Override

View File

@@ -22,7 +22,6 @@ import java.time.format.DateTimeFormatter;
import java.util.Locale;
import org.springframework.format.Formatter;
import org.springframework.lang.UsesJava8;
/**
* {@link Formatter} implementation for a JSR-310 {@link java.time.Instant},
@@ -37,7 +36,6 @@ import org.springframework.lang.UsesJava8;
* @see java.time.format.DateTimeFormatter#ISO_INSTANT
* @see java.time.format.DateTimeFormatter#RFC_1123_DATE_TIME
*/
@UsesJava8
public class InstantFormatter implements Formatter<Instant> {
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@ import java.time.MonthDay;
import java.util.Locale;
import org.springframework.format.Formatter;
import org.springframework.lang.UsesJava8;
/**
* {@link Formatter} implementation for a JSR-310 {@link MonthDay},
@@ -31,7 +30,6 @@ import org.springframework.lang.UsesJava8;
* @since 4.2.4
* @see MonthDay#parse
*/
@UsesJava8
class MonthDayFormatter implements Formatter<MonthDay> {
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@ import java.time.Period;
import java.util.Locale;
import org.springframework.format.Formatter;
import org.springframework.lang.UsesJava8;
/**
* {@link Formatter} implementation for a JSR-310 {@link Period},
@@ -31,7 +30,6 @@ import org.springframework.lang.UsesJava8;
* @since 4.2.4
* @see Period#parse
*/
@UsesJava8
class PeriodFormatter implements Formatter<Period> {
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,7 +28,6 @@ import java.time.temporal.TemporalAccessor;
import java.util.Locale;
import org.springframework.format.Parser;
import org.springframework.lang.UsesJava8;
/**
* {@link Parser} implementation for a JSR-310 {@link java.time.temporal.TemporalAccessor},
@@ -44,7 +43,6 @@ import org.springframework.lang.UsesJava8;
* @see java.time.OffsetDateTime#parse(CharSequence, java.time.format.DateTimeFormatter)
* @see java.time.OffsetTime#parse(CharSequence, java.time.format.DateTimeFormatter)
*/
@UsesJava8
public final class TemporalAccessorParser implements Parser<TemporalAccessor> {
private final Class<? extends TemporalAccessor> temporalAccessorType;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@ import java.time.temporal.TemporalAccessor;
import java.util.Locale;
import org.springframework.format.Printer;
import org.springframework.lang.UsesJava8;
/**
* {@link Printer} implementation for a JSR-310 {@link java.time.temporal.TemporalAccessor},
@@ -32,7 +31,6 @@ import org.springframework.lang.UsesJava8;
* @see DateTimeContextHolder#getFormatter
* @see java.time.format.DateTimeFormatter#format(java.time.temporal.TemporalAccessor)
*/
@UsesJava8
public final class TemporalAccessorPrinter implements Printer<TemporalAccessor> {
private final DateTimeFormatter formatter;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@ import java.time.YearMonth;
import java.util.Locale;
import org.springframework.format.Formatter;
import org.springframework.lang.UsesJava8;
/**
* {@link Formatter} implementation for a JSR-310 {@link YearMonth},
@@ -31,7 +30,6 @@ import org.springframework.lang.UsesJava8;
* @since 4.2.4
* @see YearMonth#parse
*/
@UsesJava8
class YearMonthFormatter implements Formatter<YearMonth> {
@Override

View File

@@ -52,9 +52,8 @@ import org.springframework.util.ReflectionUtils;
* web application). There is no direct API dependency between this LoadTimeWeaver
* adapter and the underlying ClassLoader, just a 'loose' method contract.
*
* <p>This is the LoadTimeWeaver to use in combination with Spring's
* {@link org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader}
* for Tomcat 5.0+ as well as with the Resin application server version 3.1+.
* <p>This is the LoadTimeWeaver to use e.g. with the Resin application server
* version 3.1+.
*
* @author Costin Leau
* @author Juergen Hoeller
@@ -62,7 +61,6 @@ import org.springframework.util.ReflectionUtils;
* @see #addTransformer(java.lang.instrument.ClassFileTransformer)
* @see #getThrowawayClassLoader()
* @see SimpleThrowawayClassLoader
* @see org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader
*/
public class ReflectiveLoadTimeWeaver implements LoadTimeWeaver {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@ package org.springframework.instrument.classloading;
import java.lang.instrument.ClassFileTransformer;
import org.springframework.core.OverridingClassLoader;
import org.springframework.lang.UsesJava7;
/**
* Simplistic implementation of an instrumentable {@code ClassLoader}.
@@ -30,13 +29,10 @@ import org.springframework.lang.UsesJava7;
* @author Costin Leau
* @since 2.0
*/
@UsesJava7
public class SimpleInstrumentableClassLoader extends OverridingClassLoader {
static {
if (parallelCapableClassLoaderAvailable) {
ClassLoader.registerAsParallelCapable();
}
ClassLoader.registerAsParallelCapable();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
package org.springframework.instrument.classloading;
import org.springframework.core.OverridingClassLoader;
import org.springframework.lang.UsesJava7;
/**
* ClassLoader that can be used to load classes without bringing them
@@ -27,13 +26,10 @@ import org.springframework.lang.UsesJava7;
* @author Rod Johnson
* @since 2.0
*/
@UsesJava7
public class SimpleThrowawayClassLoader extends OverridingClassLoader {
static {
if (parallelCapableClassLoaderAvailable) {
ClassLoader.registerAsParallelCapable();
}
ClassLoader.registerAsParallelCapable();
}

View File

@@ -26,8 +26,8 @@ import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
/**
* {@link org.springframework.instrument.classloading.LoadTimeWeaver} implementation for Tomcat's
* new {@link org.apache.tomcat.InstrumentableClassLoader InstrumentableClassLoader}.
* {@link org.springframework.instrument.classloading.LoadTimeWeaver} implementation
* for Tomcat's new {@code org.apache.tomcat.InstrumentableClassLoader}.
* Also capable of handling Spring's TomcatInstrumentableClassLoader when encountered.
*
* @author Juergen Hoeller

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,12 +22,9 @@ import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.lang.UsesJava7;
/**
* A Spring {@link FactoryBean} that builds and exposes a preconfigured {@link ForkJoinPool}.
* May be used on Java 7 and 8 as well as on Java 6 with {@code jsr166.jar} on the classpath
* (ideally on the VM bootstrap classpath).
*
* <p>For details on the ForkJoinPool API and its use with RecursiveActions, see the
* <a href="http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ForkJoinPool.html">JDK 7 javadoc</a>.
@@ -38,7 +35,6 @@ import org.springframework.lang.UsesJava7;
* @author Juergen Hoeller
* @since 3.1
*/
@UsesJava7
public class ForkJoinPoolFactoryBean implements FactoryBean<ForkJoinPool>, InitializingBean, DisposableBean {
private boolean commonPool = false;

View File

@@ -24,11 +24,9 @@ import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.lang.UsesJava7;
import org.springframework.scheduling.support.DelegatingErrorHandlingRunnable;
import org.springframework.scheduling.support.TaskUtils;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
/**
@@ -75,11 +73,6 @@ import org.springframework.util.ObjectUtils;
public class ScheduledExecutorFactoryBean extends ExecutorConfigurationSupport
implements FactoryBean<ScheduledExecutorService> {
// ScheduledThreadPoolExecutor.setRemoveOnCancelPolicy(boolean) only available on JDK 7+
private static final boolean setRemoveOnCancelPolicyAvailable =
ClassUtils.hasMethod(ScheduledThreadPoolExecutor.class, "setRemoveOnCancelPolicy", boolean.class);
private int poolSize = 1;
private ScheduledExecutorTask[] scheduledExecutorTasks;
@@ -150,7 +143,6 @@ public class ScheduledExecutorFactoryBean extends ExecutorConfigurationSupport
@Override
@UsesJava7
protected ExecutorService initializeExecutor(
ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {
@@ -158,7 +150,7 @@ public class ScheduledExecutorFactoryBean extends ExecutorConfigurationSupport
createExecutor(this.poolSize, threadFactory, rejectedExecutionHandler);
if (this.removeOnCancelPolicy) {
if (setRemoveOnCancelPolicyAvailable && executor instanceof ScheduledThreadPoolExecutor) {
if (executor instanceof ScheduledThreadPoolExecutor) {
((ScheduledThreadPoolExecutor) executor).setRemoveOnCancelPolicy(true);
}
else {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,13 +31,11 @@ import java.util.concurrent.TimeUnit;
import org.springframework.core.task.AsyncListenableTaskExecutor;
import org.springframework.core.task.TaskRejectedException;
import org.springframework.lang.UsesJava7;
import org.springframework.scheduling.SchedulingTaskExecutor;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.Trigger;
import org.springframework.scheduling.support.TaskUtils;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ErrorHandler;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.util.concurrent.ListenableFutureTask;
@@ -58,11 +56,6 @@ import org.springframework.util.concurrent.ListenableFutureTask;
public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
implements AsyncListenableTaskExecutor, SchedulingTaskExecutor, TaskScheduler {
// ScheduledThreadPoolExecutor.setRemoveOnCancelPolicy(boolean) only available on JDK 7+
private static final boolean setRemoveOnCancelPolicyAvailable =
ClassUtils.hasMethod(ScheduledThreadPoolExecutor.class, "setRemoveOnCancelPolicy", boolean.class);
private volatile int poolSize = 1;
private volatile boolean removeOnCancelPolicy = false;
@@ -91,10 +84,9 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
* switched into remove-on-cancel mode (if possible, with a soft fallback otherwise).
* <p><b>This setting can be modified at runtime, for example through JMX.</b>
*/
@UsesJava7
public void setRemoveOnCancelPolicy(boolean removeOnCancelPolicy) {
this.removeOnCancelPolicy = removeOnCancelPolicy;
if (setRemoveOnCancelPolicyAvailable && this.scheduledExecutor instanceof ScheduledThreadPoolExecutor) {
if (this.scheduledExecutor instanceof ScheduledThreadPoolExecutor) {
((ScheduledThreadPoolExecutor) this.scheduledExecutor).setRemoveOnCancelPolicy(removeOnCancelPolicy);
}
else if (removeOnCancelPolicy && this.scheduledExecutor != null) {
@@ -110,7 +102,6 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
}
@UsesJava7
@Override
protected ExecutorService initializeExecutor(
ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {
@@ -118,7 +109,7 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
this.scheduledExecutor = createExecutor(this.poolSize, threadFactory, rejectedExecutionHandler);
if (this.removeOnCancelPolicy) {
if (setRemoveOnCancelPolicyAvailable && this.scheduledExecutor instanceof ScheduledThreadPoolExecutor) {
if (this.scheduledExecutor instanceof ScheduledThreadPoolExecutor) {
((ScheduledThreadPoolExecutor) this.scheduledExecutor).setRemoveOnCancelPolicy(true);
}
else {
@@ -187,11 +178,7 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
* Return the current setting for the remove-on-cancel mode.
* <p>Requires an underlying {@link ScheduledThreadPoolExecutor}.
*/
@UsesJava7
public boolean isRemoveOnCancelPolicy() {
if (!setRemoveOnCancelPolicyAvailable) {
return false;
}
if (this.scheduledExecutor == null) {
// Not initialized yet: return our setting for the time being.
return this.removeOnCancelPolicy;

View File

@@ -24,7 +24,6 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -44,9 +43,7 @@ import org.springframework.core.MethodParameter;
import org.springframework.core.convert.ConversionService;
import org.springframework.format.Formatter;
import org.springframework.format.support.FormatterPropertyEditorAdapter;
import org.springframework.lang.UsesJava8;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.PatternMatchUtils;
import org.springframework.util.StringUtils;
@@ -124,19 +121,6 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
*/
protected static final Log logger = LogFactory.getLog(DataBinder.class);
private static Class<?> javaUtilOptionalClass = null;
static {
try {
javaUtilOptionalClass =
ClassUtils.forName("java.util.Optional", DataBinder.class.getClassLoader());
}
catch (ClassNotFoundException ex) {
// Java 8 not available - Optional references simply not supported then.
}
}
private final Object target;
private final String objectName;
@@ -183,12 +167,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
* @param objectName the name of the target object
*/
public DataBinder(Object target, String objectName) {
if (target != null && target.getClass() == javaUtilOptionalClass) {
this.target = OptionalUnwrapper.unwrap(target);
}
else {
this.target = target;
}
this.target = ObjectUtils.unwrapOptional(target);
this.objectName = objectName;
}
@@ -884,22 +863,4 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
return getBindingResult().getModel();
}
/**
* Inner class to avoid a hard dependency on Java 8.
*/
@UsesJava8
private static class OptionalUnwrapper {
public static Object unwrap(Object optionalObject) {
Optional<?> optional = (Optional<?>) optionalObject;
if (!optional.isPresent()) {
return null;
}
Object result = optional.get();
Assert.isTrue(!(result instanceof Optional), "Multi-level Optional usage not supported");
return result;
}
}
}