Skip to content

Commit 8c2aba6

Browse files
authored
Merge pull request #3372 from harawata/drop-java8-fallback
Drop java8 fallback
2 parents 0f40136 + 68bba51 commit 8c2aba6

File tree

13 files changed

+25
-196
lines changed

13 files changed

+25
-196
lines changed

src/main/java/org/apache/ibatis/binding/MapperProxy.java

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2024 the original author or authors.
2+
* Copyright 2009-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,15 +20,13 @@
2020
import java.lang.invoke.MethodHandles;
2121
import java.lang.invoke.MethodHandles.Lookup;
2222
import java.lang.invoke.MethodType;
23-
import java.lang.reflect.Constructor;
2423
import java.lang.reflect.InvocationHandler;
2524
import java.lang.reflect.InvocationTargetException;
2625
import java.lang.reflect.Method;
2726
import java.util.Map;
2827

2928
import org.apache.ibatis.reflection.ExceptionUtil;
3029
import org.apache.ibatis.session.SqlSession;
31-
import org.apache.ibatis.util.MapUtil;
3230

3331
/**
3432
* @author Clinton Begin
@@ -37,9 +35,6 @@
3735
public class MapperProxy<T> implements InvocationHandler, Serializable {
3836

3937
private static final long serialVersionUID = -4724728412955527868L;
40-
private static final int ALLOWED_MODES = MethodHandles.Lookup.PRIVATE | MethodHandles.Lookup.PROTECTED
41-
| MethodHandles.Lookup.PACKAGE | MethodHandles.Lookup.PUBLIC;
42-
private static final Constructor<Lookup> lookupConstructor;
4338
private static final Method privateLookupInMethod;
4439
private final SqlSession sqlSession;
4540
private final Class<T> mapperInterface;
@@ -52,29 +47,12 @@ public MapperProxy(SqlSession sqlSession, Class<T> mapperInterface, Map<Method,
5247
}
5348

5449
static {
55-
Method privateLookupIn;
5650
try {
57-
privateLookupIn = MethodHandles.class.getMethod("privateLookupIn", Class.class, MethodHandles.Lookup.class);
51+
privateLookupInMethod = MethodHandles.class.getMethod("privateLookupIn", Class.class, MethodHandles.Lookup.class);
5852
} catch (NoSuchMethodException e) {
59-
privateLookupIn = null;
53+
throw new IllegalStateException(
54+
"There is no 'privateLookupIn(Class, Lookup)' method in java.lang.invoke.MethodHandles.", e);
6055
}
61-
privateLookupInMethod = privateLookupIn;
62-
63-
Constructor<Lookup> lookup = null;
64-
if (privateLookupInMethod == null) {
65-
// JDK 1.8
66-
try {
67-
lookup = MethodHandles.Lookup.class.getDeclaredConstructor(Class.class, int.class);
68-
lookup.setAccessible(true);
69-
} catch (NoSuchMethodException e) {
70-
throw new IllegalStateException(
71-
"There is neither 'privateLookupIn(Class, Lookup)' nor 'Lookup(Class, int)' method in java.lang.invoke.MethodHandles.",
72-
e);
73-
} catch (Exception e) {
74-
lookup = null;
75-
}
76-
}
77-
lookupConstructor = lookup;
7856
}
7957

8058
@Override
@@ -91,17 +69,13 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
9169

9270
private MapperMethodInvoker cachedInvoker(Method method) throws Throwable {
9371
try {
94-
return MapUtil.computeIfAbsent(methodCache, method, m -> {
72+
return methodCache.computeIfAbsent(method, m -> {
9573
if (!m.isDefault()) {
9674
return new PlainMethodInvoker(new MapperMethod(mapperInterface, method, sqlSession.getConfiguration()));
9775
}
9876
try {
99-
if (privateLookupInMethod == null) {
100-
return new DefaultMethodInvoker(getMethodHandleJava8(method));
101-
}
10277
return new DefaultMethodInvoker(getMethodHandleJava9(method));
103-
} catch (IllegalAccessException | InstantiationException | InvocationTargetException
104-
| NoSuchMethodException e) {
78+
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
10579
throw new RuntimeException(e);
10680
}
10781
});
@@ -119,12 +93,6 @@ private MethodHandle getMethodHandleJava9(Method method)
11993
declaringClass);
12094
}
12195

122-
private MethodHandle getMethodHandleJava8(Method method)
123-
throws IllegalAccessException, InstantiationException, InvocationTargetException {
124-
final Class<?> declaringClass = method.getDeclaringClass();
125-
return lookupConstructor.newInstance(declaringClass, ALLOWED_MODES).unreflectSpecial(method, declaringClass);
126-
}
127-
12896
interface MapperMethodInvoker {
12997
Object invoke(Object proxy, Method method, Object[] args, SqlSession sqlSession) throws Throwable;
13098
}

src/main/java/org/apache/ibatis/cache/TransactionalCacheManager.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2022 the original author or authors.
2+
* Copyright 2009-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@
1919
import java.util.Map;
2020

2121
import org.apache.ibatis.cache.decorators.TransactionalCache;
22-
import org.apache.ibatis.util.MapUtil;
2322

2423
/**
2524
* @author Clinton Begin
@@ -53,7 +52,7 @@ public void rollback() {
5352
}
5453

5554
private TransactionalCache getTransactionalCache(Cache cache) {
56-
return MapUtil.computeIfAbsent(transactionalCaches, cache, TransactionalCache::new);
55+
return transactionalCaches.computeIfAbsent(cache, TransactionalCache::new);
5756
}
5857

5958
}

src/main/java/org/apache/ibatis/datasource/unpooled/UnpooledDataSource.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2024 the original author or authors.
2+
* Copyright 2009-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,7 +31,6 @@
3131
import javax.sql.DataSource;
3232

3333
import org.apache.ibatis.io.Resources;
34-
import org.apache.ibatis.util.MapUtil;
3534

3635
/**
3736
* @author Clinton Begin
@@ -233,7 +232,7 @@ private Connection doGetConnection(Properties properties) throws SQLException {
233232

234233
private void initializeDriver() throws SQLException {
235234
try {
236-
MapUtil.computeIfAbsent(registeredDrivers, driver, x -> {
235+
registeredDrivers.computeIfAbsent(driver, x -> {
237236
Class<?> driverType;
238237
try {
239238
if (driverClassLoader != null) {

src/main/java/org/apache/ibatis/executor/keygen/Jdbc3KeyGenerator.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2024 the original author or authors.
2+
* Copyright 2009-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,7 +41,6 @@
4141
import org.apache.ibatis.type.JdbcType;
4242
import org.apache.ibatis.type.TypeHandler;
4343
import org.apache.ibatis.type.TypeHandlerRegistry;
44-
import org.apache.ibatis.util.MapUtil;
4544

4645
/**
4746
* @author Clinton Begin
@@ -156,8 +155,8 @@ private void assignKeysToParamMap(Configuration configuration, ResultSet rs, Res
156155
for (int i = 0; i < keyProperties.length; i++) {
157156
Entry<String, KeyAssigner> entry = getAssignerForParamMap(configuration, rsmd, i + 1, paramMap, keyProperties[i],
158157
keyProperties, true);
159-
Entry<Iterator<?>, List<KeyAssigner>> iteratorPair = MapUtil.computeIfAbsent(assignerMap, entry.getKey(),
160-
k -> MapUtil.entry(collectionize(paramMap.get(k)).iterator(), new ArrayList<>()));
158+
Entry<Iterator<?>, List<KeyAssigner>> iteratorPair = assignerMap.computeIfAbsent(entry.getKey(),
159+
k -> Map.entry(collectionize(paramMap.get(k)).iterator(), new ArrayList<>()));
161160
iteratorPair.getValue().add(entry.getValue());
162161
}
163162
long counter = 0;
@@ -193,7 +192,7 @@ private Entry<String, KeyAssigner> getAssignerForParamMap(Configuration config,
193192
if (keySet.contains(paramName)) {
194193
String argParamName = omitParamName ? null : paramName;
195194
String argKeyProperty = keyProperty.substring(firstDot + 1);
196-
return MapUtil.entry(paramName, new KeyAssigner(config, rsmd, columnPosition, argParamName, argKeyProperty));
195+
return Map.entry(paramName, new KeyAssigner(config, rsmd, columnPosition, argParamName, argKeyProperty));
197196
}
198197
if (singleParam) {
199198
return getAssignerForSingleParam(config, rsmd, columnPosition, paramMap, keyProperty, omitParamName);
@@ -210,7 +209,7 @@ private Entry<String, KeyAssigner> getAssignerForSingleParam(Configuration confi
210209
// Assume 'keyProperty' to be a property of the single param.
211210
String singleParamName = nameOfSingleParam(paramMap);
212211
String argParamName = omitParamName ? null : singleParamName;
213-
return MapUtil.entry(singleParamName, new KeyAssigner(config, rsmd, columnPosition, argParamName, keyProperty));
212+
return Map.entry(singleParamName, new KeyAssigner(config, rsmd, columnPosition, argParamName, keyProperty));
214213
}
215214

216215
private static String nameOfSingleParam(Map<String, ?> paramMap) {

src/main/java/org/apache/ibatis/executor/resultset/DefaultResultSetHandler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
import org.apache.ibatis.type.JdbcType;
6969
import org.apache.ibatis.type.TypeHandler;
7070
import org.apache.ibatis.type.TypeHandlerRegistry;
71-
import org.apache.ibatis.util.MapUtil;
7271

7372
/**
7473
* @author Clinton Begin
@@ -651,7 +650,7 @@ private void addPendingChildRelation(ResultSet rs, MetaObject metaResultObject,
651650
PendingRelation deferLoad = new PendingRelation();
652651
deferLoad.metaObject = metaResultObject;
653652
deferLoad.propertyMapping = parentMapping;
654-
List<PendingRelation> relations = MapUtil.computeIfAbsent(pendingRelations, cacheKey, k -> new ArrayList<>());
653+
List<PendingRelation> relations = pendingRelations.computeIfAbsent(cacheKey, k -> new ArrayList<>());
655654
// issue #255
656655
relations.add(deferLoad);
657656
ResultMapping previous = nextResultMaps.get(parentMapping.getResultSet());
@@ -877,7 +876,7 @@ private boolean applyArgNameBasedConstructorAutoMapping(ResultSetWrapper rsw, Re
877876
constructorArgs.add(value);
878877
final String mapKey = resultMap.getId() + ":" + columnPrefix;
879878
if (!autoMappingsCache.containsKey(mapKey)) {
880-
MapUtil.computeIfAbsent(constructorAutoMappingColumns, mapKey, k -> new ArrayList<>()).add(columnName);
879+
constructorAutoMappingColumns.computeIfAbsent(mapKey, k -> new ArrayList<>()).add(columnName);
881880
}
882881
columnNotFound = false;
883882
foundValues = value != null || foundValues;

src/main/java/org/apache/ibatis/lang/UsesJava7.java

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/main/java/org/apache/ibatis/lang/UsesJava8.java

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/main/java/org/apache/ibatis/lang/package-info.java

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/main/java/org/apache/ibatis/plugin/Plugin.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2023 the original author or authors.
2+
* Copyright 2009-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,7 +24,6 @@
2424
import java.util.Set;
2525

2626
import org.apache.ibatis.reflection.ExceptionUtil;
27-
import org.apache.ibatis.util.MapUtil;
2827

2928
/**
3029
* @author Clinton Begin
@@ -74,7 +73,7 @@ private static Map<Class<?>, Set<Method>> getSignatureMap(Interceptor intercepto
7473
Signature[] sigs = interceptsAnnotation.value();
7574
Map<Class<?>, Set<Method>> signatureMap = new HashMap<>();
7675
for (Signature sig : sigs) {
77-
Set<Method> methods = MapUtil.computeIfAbsent(signatureMap, sig.type(), k -> new HashSet<>());
76+
Set<Method> methods = signatureMap.computeIfAbsent(sig.type(), k -> new HashSet<>());
7877
try {
7978
Method method = sig.type().getMethod(sig.method(), sig.args());
8079
methods.add(method);

src/main/java/org/apache/ibatis/reflection/DefaultReflectorFactory.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2023 the original author or authors.
2+
* Copyright 2009-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,8 +18,6 @@
1818
import java.util.concurrent.ConcurrentHashMap;
1919
import java.util.concurrent.ConcurrentMap;
2020

21-
import org.apache.ibatis.util.MapUtil;
22-
2321
public class DefaultReflectorFactory implements ReflectorFactory {
2422
private boolean classCacheEnabled = true;
2523
private final ConcurrentMap<Class<?>, Reflector> reflectorMap = new ConcurrentHashMap<>();
@@ -41,7 +39,7 @@ public void setClassCacheEnabled(boolean classCacheEnabled) {
4139
public Reflector findForClass(Class<?> type) {
4240
if (classCacheEnabled) {
4341
// synchronized (type) removed see issue #461
44-
return MapUtil.computeIfAbsent(reflectorMap, type, Reflector::new);
42+
return reflectorMap.computeIfAbsent(type, Reflector::new);
4543
}
4644
return new Reflector(type);
4745
}

src/main/java/org/apache/ibatis/reflection/Reflector.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2024 the original author or authors.
2+
* Copyright 2009-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -43,7 +43,6 @@
4343
import org.apache.ibatis.reflection.invoker.MethodInvoker;
4444
import org.apache.ibatis.reflection.invoker.SetFieldInvoker;
4545
import org.apache.ibatis.reflection.property.PropertyNamer;
46-
import org.apache.ibatis.util.MapUtil;
4746

4847
/**
4948
* This class represents a cached set of class definition information that allows for easy mapping between property
@@ -155,7 +154,7 @@ private void addSetMethods(Method[] methods) {
155154

156155
private void addMethodConflict(Map<String, List<Method>> conflictingMethods, String name, Method method) {
157156
if (isValidPropertyName(name)) {
158-
List<Method> list = MapUtil.computeIfAbsent(conflictingMethods, name, k -> new ArrayList<>());
157+
List<Method> list = conflictingMethods.computeIfAbsent(name, k -> new ArrayList<>());
159158
list.add(method);
160159
}
161160
}

src/main/java/org/apache/ibatis/scripting/LanguageDriverRegistry.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2024 the original author or authors.
2+
* Copyright 2009-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,8 +18,6 @@
1818
import java.util.HashMap;
1919
import java.util.Map;
2020

21-
import org.apache.ibatis.util.MapUtil;
22-
2321
/**
2422
* @author Frank D. Martinez [mnesarco]
2523
*/
@@ -33,7 +31,7 @@ public void register(Class<? extends LanguageDriver> cls) {
3331
if (cls == null) {
3432
throw new IllegalArgumentException("null is not a valid Language Driver");
3533
}
36-
MapUtil.computeIfAbsent(languageDriverMap, cls, k -> {
34+
languageDriverMap.computeIfAbsent(cls, k -> {
3735
try {
3836
return k.getDeclaredConstructor().newInstance();
3937
} catch (Exception ex) {

0 commit comments

Comments
 (0)