diff --git a/src/main/java/org/apache/ibatis/binding/MapperProxy.java b/src/main/java/org/apache/ibatis/binding/MapperProxy.java index 80c774da23a..4f3399199b8 100644 --- a/src/main/java/org/apache/ibatis/binding/MapperProxy.java +++ b/src/main/java/org/apache/ibatis/binding/MapperProxy.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2024 the original author or authors. + * Copyright 2009-2025 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.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles.Lookup; import java.lang.invoke.MethodType; -import java.lang.reflect.Constructor; import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -28,7 +27,6 @@ import org.apache.ibatis.reflection.ExceptionUtil; import org.apache.ibatis.session.SqlSession; -import org.apache.ibatis.util.MapUtil; /** * @author Clinton Begin @@ -37,9 +35,6 @@ public class MapperProxy implements InvocationHandler, Serializable { private static final long serialVersionUID = -4724728412955527868L; - private static final int ALLOWED_MODES = MethodHandles.Lookup.PRIVATE | MethodHandles.Lookup.PROTECTED - | MethodHandles.Lookup.PACKAGE | MethodHandles.Lookup.PUBLIC; - private static final Constructor lookupConstructor; private static final Method privateLookupInMethod; private final SqlSession sqlSession; private final Class mapperInterface; @@ -52,29 +47,12 @@ public MapperProxy(SqlSession sqlSession, Class mapperInterface, Map lookup = null; - if (privateLookupInMethod == null) { - // JDK 1.8 - try { - lookup = MethodHandles.Lookup.class.getDeclaredConstructor(Class.class, int.class); - lookup.setAccessible(true); - } catch (NoSuchMethodException e) { - throw new IllegalStateException( - "There is neither 'privateLookupIn(Class, Lookup)' nor 'Lookup(Class, int)' method in java.lang.invoke.MethodHandles.", - e); - } catch (Exception e) { - lookup = null; - } - } - lookupConstructor = lookup; } @Override @@ -91,17 +69,13 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl private MapperMethodInvoker cachedInvoker(Method method) throws Throwable { try { - return MapUtil.computeIfAbsent(methodCache, method, m -> { + return methodCache.computeIfAbsent(method, m -> { if (!m.isDefault()) { return new PlainMethodInvoker(new MapperMethod(mapperInterface, method, sqlSession.getConfiguration())); } try { - if (privateLookupInMethod == null) { - return new DefaultMethodInvoker(getMethodHandleJava8(method)); - } return new DefaultMethodInvoker(getMethodHandleJava9(method)); - } catch (IllegalAccessException | InstantiationException | InvocationTargetException - | NoSuchMethodException e) { + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { throw new RuntimeException(e); } }); @@ -119,12 +93,6 @@ private MethodHandle getMethodHandleJava9(Method method) declaringClass); } - private MethodHandle getMethodHandleJava8(Method method) - throws IllegalAccessException, InstantiationException, InvocationTargetException { - final Class declaringClass = method.getDeclaringClass(); - return lookupConstructor.newInstance(declaringClass, ALLOWED_MODES).unreflectSpecial(method, declaringClass); - } - interface MapperMethodInvoker { Object invoke(Object proxy, Method method, Object[] args, SqlSession sqlSession) throws Throwable; } diff --git a/src/main/java/org/apache/ibatis/cache/TransactionalCacheManager.java b/src/main/java/org/apache/ibatis/cache/TransactionalCacheManager.java index 88cae573c2e..9c8f5951ec8 100644 --- a/src/main/java/org/apache/ibatis/cache/TransactionalCacheManager.java +++ b/src/main/java/org/apache/ibatis/cache/TransactionalCacheManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2022 the original author or authors. + * Copyright 2009-2025 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 @@ import java.util.Map; import org.apache.ibatis.cache.decorators.TransactionalCache; -import org.apache.ibatis.util.MapUtil; /** * @author Clinton Begin @@ -53,7 +52,7 @@ public void rollback() { } private TransactionalCache getTransactionalCache(Cache cache) { - return MapUtil.computeIfAbsent(transactionalCaches, cache, TransactionalCache::new); + return transactionalCaches.computeIfAbsent(cache, TransactionalCache::new); } } diff --git a/src/main/java/org/apache/ibatis/datasource/unpooled/UnpooledDataSource.java b/src/main/java/org/apache/ibatis/datasource/unpooled/UnpooledDataSource.java index 1b5c769d7c6..bb436054cd0 100644 --- a/src/main/java/org/apache/ibatis/datasource/unpooled/UnpooledDataSource.java +++ b/src/main/java/org/apache/ibatis/datasource/unpooled/UnpooledDataSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2024 the original author or authors. + * Copyright 2009-2025 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,7 +31,6 @@ import javax.sql.DataSource; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.util.MapUtil; /** * @author Clinton Begin @@ -233,7 +232,7 @@ private Connection doGetConnection(Properties properties) throws SQLException { private void initializeDriver() throws SQLException { try { - MapUtil.computeIfAbsent(registeredDrivers, driver, x -> { + registeredDrivers.computeIfAbsent(driver, x -> { Class driverType; try { if (driverClassLoader != null) { diff --git a/src/main/java/org/apache/ibatis/executor/keygen/Jdbc3KeyGenerator.java b/src/main/java/org/apache/ibatis/executor/keygen/Jdbc3KeyGenerator.java index fad23476cfb..69056a90384 100644 --- a/src/main/java/org/apache/ibatis/executor/keygen/Jdbc3KeyGenerator.java +++ b/src/main/java/org/apache/ibatis/executor/keygen/Jdbc3KeyGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2024 the original author or authors. + * Copyright 2009-2025 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. @@ -41,7 +41,6 @@ import org.apache.ibatis.type.JdbcType; import org.apache.ibatis.type.TypeHandler; import org.apache.ibatis.type.TypeHandlerRegistry; -import org.apache.ibatis.util.MapUtil; /** * @author Clinton Begin @@ -156,8 +155,8 @@ private void assignKeysToParamMap(Configuration configuration, ResultSet rs, Res for (int i = 0; i < keyProperties.length; i++) { Entry entry = getAssignerForParamMap(configuration, rsmd, i + 1, paramMap, keyProperties[i], keyProperties, true); - Entry, List> iteratorPair = MapUtil.computeIfAbsent(assignerMap, entry.getKey(), - k -> MapUtil.entry(collectionize(paramMap.get(k)).iterator(), new ArrayList<>())); + Entry, List> iteratorPair = assignerMap.computeIfAbsent(entry.getKey(), + k -> Map.entry(collectionize(paramMap.get(k)).iterator(), new ArrayList<>())); iteratorPair.getValue().add(entry.getValue()); } long counter = 0; @@ -193,7 +192,7 @@ private Entry getAssignerForParamMap(Configuration config, if (keySet.contains(paramName)) { String argParamName = omitParamName ? null : paramName; String argKeyProperty = keyProperty.substring(firstDot + 1); - return MapUtil.entry(paramName, new KeyAssigner(config, rsmd, columnPosition, argParamName, argKeyProperty)); + return Map.entry(paramName, new KeyAssigner(config, rsmd, columnPosition, argParamName, argKeyProperty)); } if (singleParam) { return getAssignerForSingleParam(config, rsmd, columnPosition, paramMap, keyProperty, omitParamName); @@ -210,7 +209,7 @@ private Entry getAssignerForSingleParam(Configuration confi // Assume 'keyProperty' to be a property of the single param. String singleParamName = nameOfSingleParam(paramMap); String argParamName = omitParamName ? null : singleParamName; - return MapUtil.entry(singleParamName, new KeyAssigner(config, rsmd, columnPosition, argParamName, keyProperty)); + return Map.entry(singleParamName, new KeyAssigner(config, rsmd, columnPosition, argParamName, keyProperty)); } private static String nameOfSingleParam(Map paramMap) { diff --git a/src/main/java/org/apache/ibatis/executor/resultset/DefaultResultSetHandler.java b/src/main/java/org/apache/ibatis/executor/resultset/DefaultResultSetHandler.java index c089302a254..27fa35988b1 100644 --- a/src/main/java/org/apache/ibatis/executor/resultset/DefaultResultSetHandler.java +++ b/src/main/java/org/apache/ibatis/executor/resultset/DefaultResultSetHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2024 the original author or authors. + * Copyright 2009-2025 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. @@ -66,7 +66,6 @@ import org.apache.ibatis.type.JdbcType; import org.apache.ibatis.type.TypeHandler; import org.apache.ibatis.type.TypeHandlerRegistry; -import org.apache.ibatis.util.MapUtil; /** * @author Clinton Begin @@ -618,7 +617,7 @@ private void addPendingChildRelation(ResultSet rs, MetaObject metaResultObject, PendingRelation deferLoad = new PendingRelation(); deferLoad.metaObject = metaResultObject; deferLoad.propertyMapping = parentMapping; - List relations = MapUtil.computeIfAbsent(pendingRelations, cacheKey, k -> new ArrayList<>()); + List relations = pendingRelations.computeIfAbsent(cacheKey, k -> new ArrayList<>()); // issue #255 relations.add(deferLoad); ResultMapping previous = nextResultMaps.get(parentMapping.getResultSet()); @@ -820,7 +819,7 @@ private boolean applyArgNameBasedConstructorAutoMapping(ResultSetWrapper rsw, Re constructorArgs.add(value); final String mapKey = resultMap.getId() + ":" + columnPrefix; if (!autoMappingsCache.containsKey(mapKey)) { - MapUtil.computeIfAbsent(constructorAutoMappingColumns, mapKey, k -> new ArrayList<>()).add(columnName); + constructorAutoMappingColumns.computeIfAbsent(mapKey, k -> new ArrayList<>()).add(columnName); } columnNotFound = false; foundValues = value != null || foundValues; diff --git a/src/main/java/org/apache/ibatis/lang/UsesJava7.java b/src/main/java/org/apache/ibatis/lang/UsesJava7.java deleted file mode 100644 index 29763663796..00000000000 --- a/src/main/java/org/apache/ibatis/lang/UsesJava7.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2009-2024 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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ibatis.lang; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Indicates that the element uses Java 7 API. - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.FIELD }) -public @interface UsesJava7 { -} diff --git a/src/main/java/org/apache/ibatis/lang/UsesJava8.java b/src/main/java/org/apache/ibatis/lang/UsesJava8.java deleted file mode 100644 index 4dfcaee0957..00000000000 --- a/src/main/java/org/apache/ibatis/lang/UsesJava8.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2009-2024 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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ibatis.lang; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Indicates that the element uses Java 8 API. - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.FIELD }) -public @interface UsesJava8 { -} diff --git a/src/main/java/org/apache/ibatis/lang/package-info.java b/src/main/java/org/apache/ibatis/lang/package-info.java deleted file mode 100644 index d852561738d..00000000000 --- a/src/main/java/org/apache/ibatis/lang/package-info.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright 2009-2022 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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * Java Language Package. - */ -package org.apache.ibatis.lang; diff --git a/src/main/java/org/apache/ibatis/plugin/Plugin.java b/src/main/java/org/apache/ibatis/plugin/Plugin.java index e4f829221ed..feae8724c84 100644 --- a/src/main/java/org/apache/ibatis/plugin/Plugin.java +++ b/src/main/java/org/apache/ibatis/plugin/Plugin.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2023 the original author or authors. + * Copyright 2009-2025 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.Set; import org.apache.ibatis.reflection.ExceptionUtil; -import org.apache.ibatis.util.MapUtil; /** * @author Clinton Begin @@ -74,7 +73,7 @@ private static Map, Set> getSignatureMap(Interceptor intercepto Signature[] sigs = interceptsAnnotation.value(); Map, Set> signatureMap = new HashMap<>(); for (Signature sig : sigs) { - Set methods = MapUtil.computeIfAbsent(signatureMap, sig.type(), k -> new HashSet<>()); + Set methods = signatureMap.computeIfAbsent(sig.type(), k -> new HashSet<>()); try { Method method = sig.type().getMethod(sig.method(), sig.args()); methods.add(method); diff --git a/src/main/java/org/apache/ibatis/reflection/DefaultReflectorFactory.java b/src/main/java/org/apache/ibatis/reflection/DefaultReflectorFactory.java index eff6c7f896c..fa7886d6275 100644 --- a/src/main/java/org/apache/ibatis/reflection/DefaultReflectorFactory.java +++ b/src/main/java/org/apache/ibatis/reflection/DefaultReflectorFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2023 the original author or authors. + * Copyright 2009-2025 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. @@ -18,8 +18,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import org.apache.ibatis.util.MapUtil; - public class DefaultReflectorFactory implements ReflectorFactory { private boolean classCacheEnabled = true; private final ConcurrentMap, Reflector> reflectorMap = new ConcurrentHashMap<>(); @@ -41,7 +39,7 @@ public void setClassCacheEnabled(boolean classCacheEnabled) { public Reflector findForClass(Class type) { if (classCacheEnabled) { // synchronized (type) removed see issue #461 - return MapUtil.computeIfAbsent(reflectorMap, type, Reflector::new); + return reflectorMap.computeIfAbsent(type, Reflector::new); } return new Reflector(type); } diff --git a/src/main/java/org/apache/ibatis/reflection/Reflector.java b/src/main/java/org/apache/ibatis/reflection/Reflector.java index 7ae50d0e0d5..2599c53dbf7 100644 --- a/src/main/java/org/apache/ibatis/reflection/Reflector.java +++ b/src/main/java/org/apache/ibatis/reflection/Reflector.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2024 the original author or authors. + * Copyright 2009-2025 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. @@ -43,7 +43,6 @@ import org.apache.ibatis.reflection.invoker.MethodInvoker; import org.apache.ibatis.reflection.invoker.SetFieldInvoker; import org.apache.ibatis.reflection.property.PropertyNamer; -import org.apache.ibatis.util.MapUtil; /** * 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) { private void addMethodConflict(Map> conflictingMethods, String name, Method method) { if (isValidPropertyName(name)) { - List list = MapUtil.computeIfAbsent(conflictingMethods, name, k -> new ArrayList<>()); + List list = conflictingMethods.computeIfAbsent(name, k -> new ArrayList<>()); list.add(method); } } diff --git a/src/main/java/org/apache/ibatis/scripting/LanguageDriverRegistry.java b/src/main/java/org/apache/ibatis/scripting/LanguageDriverRegistry.java index cfe44257e22..aa571153ab4 100644 --- a/src/main/java/org/apache/ibatis/scripting/LanguageDriverRegistry.java +++ b/src/main/java/org/apache/ibatis/scripting/LanguageDriverRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2024 the original author or authors. + * Copyright 2009-2025 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. @@ -18,8 +18,6 @@ import java.util.HashMap; import java.util.Map; -import org.apache.ibatis.util.MapUtil; - /** * @author Frank D. Martinez [mnesarco] */ @@ -33,7 +31,7 @@ public void register(Class cls) { if (cls == null) { throw new IllegalArgumentException("null is not a valid Language Driver"); } - MapUtil.computeIfAbsent(languageDriverMap, cls, k -> { + languageDriverMap.computeIfAbsent(cls, k -> { try { return k.getDeclaredConstructor().newInstance(); } catch (Exception ex) { diff --git a/src/main/java/org/apache/ibatis/util/MapUtil.java b/src/main/java/org/apache/ibatis/util/MapUtil.java deleted file mode 100644 index 6ac26fa744a..00000000000 --- a/src/main/java/org/apache/ibatis/util/MapUtil.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2009-2023 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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ibatis.util; - -import java.util.AbstractMap; -import java.util.Map; -import java.util.Map.Entry; -import java.util.function.Function; - -public class MapUtil { - /** - * A temporary workaround for Java 8 specific performance issue JDK-8161372 .
- * This class should be removed once we drop Java 8 support. - * - * @see https://bugs.openjdk.java.net/browse/JDK-8161372 - */ - public static V computeIfAbsent(Map map, K key, Function mappingFunction) { - V value = map.get(key); - if (value != null) { - return value; - } - return map.computeIfAbsent(key, mappingFunction); - } - - /** - * Map.entry(key, value) alternative for Java 8. - */ - public static Entry entry(K key, V value) { - return new AbstractMap.SimpleImmutableEntry<>(key, value); - } - - private MapUtil() { - } -}