<commit_before>/*
 * $Id$
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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
 *
 *  http://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.commons.ognl;

import org.apache.commons.ognl.enhance.ExpressionCompiler;
import org.apache.commons.ognl.enhance.OgnlExpressionCompiler;
import org.apache.commons.ognl.internal.Cache;
import org.apache.commons.ognl.internal.CacheException;
import org.apache.commons.ognl.internal.CacheFactory;
import org.apache.commons.ognl.internal.ClassCache;
import org.apache.commons.ognl.internal.ClassCacheHandler;
import org.apache.commons.ognl.internal.ConcurrentHashMapCacheFactory;
import org.apache.commons.ognl.internal.entry.CacheEntryFactory;
import org.apache.commons.ognl.internal.entry.ClassCacheEntryFactory;
import org.apache.commons.ognl.internal.entry.DeclaredMethodCacheEntry;
import org.apache.commons.ognl.internal.entry.DeclaredMethodCacheEntryFactory;
import org.apache.commons.ognl.internal.entry.FiedlCacheEntryFactory;
import org.apache.commons.ognl.internal.entry.GenericMethodParameterTypeCacheEntry;
import org.apache.commons.ognl.internal.entry.GenericMethodParameterTypeFactory;
import org.apache.commons.ognl.internal.entry.MethodAccessCacheEntryFactory;
import org.apache.commons.ognl.internal.entry.MethodAccessEntryValue;
import org.apache.commons.ognl.internal.entry.MethodPermCacheEntryFactory;
import org.apache.commons.ognl.internal.entry.PermissionCacheEntry;
import org.apache.commons.ognl.internal.entry.PermissionCacheEntryFactory;
import org.apache.commons.ognl.internal.entry.PropertyDescriptorCacheEntryFactory;

import java.beans.BeanInfo;
import java.beans.IndexedPropertyDescriptor;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.MethodDescriptor;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Proxy;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.security.Permission;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Utility class used by internal OGNL API to do various things like:
 * <ul>
 * <li>Handles majority of reflection logic / caching.</li>
 * <li>Utility methods for casting strings / various numeric types used by {@link OgnlExpressionCompiler}.</li.
 * <li>Core runtime configuration point for setting/using global {@link TypeConverter} / {@link OgnlExpressionCompiler}
 * / {@link NullHandler} instances / etc..</li>
 * </ul>
 *
 * @author <NAME> (<EMAIL>)
 * @author <NAME> (<EMAIL>)
 */
public class OgnlRuntime
{

    /**
     * Constant expression used to indicate that a given method / property couldn't be found during reflection
     * operations.
     */
    public static final Object NotFound = new Object( );

    public static final Object[] NoArguments = new Object[]{ };

    public static final Class<?>[] NoArgumentTypes = new Class<?>[]{ };

    /**
     * Token returned by TypeConverter for no conversion possible
     */
    public static final Object NoConversionPossible = "ognl.NoConversionPossible";

    /**
     * Not an indexed property
     */
    public static int INDEXED_PROPERTY_NONE = 0;

    /**
     * JavaBeans IndexedProperty
     */
    public static int INDEXED_PROPERTY_INT = 1;

    /**
     * OGNL ObjectIndexedProperty
     */
    public static int INDEXED_PROPERTY_OBJECT = 2;

    /**
     * Constant string representation of null string.
     */
    public static final String NULL_STRING = "" + null;

    /**
     * Java beans standard set method prefix.
     */
    private static final String SET_PREFIX = "set";

    /**
     * Java beans standard get method prefix.
     */
    private static final String GET_PREFIX = "get";

    /**
     * Java beans standard is<Foo> boolean getter prefix.
     */
    private static final String IS_PREFIX = "is";

    /**
     * Prefix padding for hexadecimal numbers to HEX_LENGTH.
     */
    private static final Map<Integer, String> HEX_PADDING = new HashMap<Integer, String>( );

    private static final int HEX_LENGTH = 8;

    /**
     * Returned by <CODE>getUniqueDescriptor()</CODE> when the object is <CODE>null</CODE>.
     */
    private static final String NULL_OBJECT_STRING = "<null>";

    /**
     * Used to store the result of determining if current jvm is 1.5 language compatible.
     */
    private static boolean _jdk15 = false;

    private static boolean _jdkChecked = false;

    private static CacheFactory cacheFactory = new ConcurrentHashMapCacheFactory( );

    static final ClassCache<MethodAccessor> _methodAccessors = cacheFactory.createClassCache( );

    static final ClassCache<PropertyAccessor> _propertyAccessors = cacheFactory.createClassCache( );

    static final ClassCache<ElementsAccessor> _elementsAccessors = cacheFactory.createClassCache( );

    static final ClassCache<NullHandler> _nullHandlers = cacheFactory.createClassCache( );

    static final ClassCache<Map<String, PropertyDescriptor>> _propertyDescriptorCache =
        cacheFactory.createClassCache( new PropertyDescriptorCacheEntryFactory( ) );

    static final ClassCache<List<Constructor<?>>> _constructorCache =
        cacheFactory.createClassCache( new ClassCacheEntryFactory<List<Constructor<?>>>( )
        {
            public List<Constructor<?>> create( Class<?> key )
                throws CacheException
            {
                return Arrays.asList( key.getConstructors( ) );
            }
        } );

    static final Cache<DeclaredMethodCacheEntry, Map<String, List<Method>>> _methodCache =
        cacheFactory.createCache( new DeclaredMethodCacheEntryFactory( ) );

    static final Cache<PermissionCacheEntry, Permission> _invokePermissionCache =
        cacheFactory.createCache( new PermissionCacheEntryFactory( ) );

    static final ClassCache<Map<String, Field>> _fieldCache =
        cacheFactory.createClassCache( new FiedlCacheEntryFactory( ) );

    static final Map<String, Class<?>> _primitiveTypes = new HashMap<String, Class<?>>( 101 );

    static final HashMap<Class<?>, Object> _primitiveDefaults = new HashMap<Class<?>, Object>( 20 );

    static final Cache<Method, Class<?>[]> _methodParameterTypesCache =
        cacheFactory.createCache( new CacheEntryFactory<Method, Class<?>[]>( )
        {
            public Class<?>[] create( Method key )
                throws CacheException
            {
                return key.getParameterTypes( );
            }
        } );

    static final Cache<GenericMethodParameterTypeCacheEntry, Class<?>[]> _genericMethodParameterTypesCache =
        cacheFactory.createCache( new GenericMethodParameterTypeFactory( ) );
<commit_msg>Better interface where possible<commit_after>/*
 * $Id$
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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
 *
 *  http://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.commons.ognl;

import org.apache.commons.ognl.enhance.ExpressionCompiler;
import org.apache.commons.ognl.enhance.OgnlExpressionCompiler;
import org.apache.commons.ognl.internal.Cache;
import org.apache.commons.ognl.internal.CacheException;
import org.apache.commons.ognl.internal.CacheFactory;
import org.apache.commons.ognl.internal.ClassCache;
import org.apache.commons.ognl.internal.ClassCacheHandler;
import org.apache.commons.ognl.internal.ConcurrentHashMapCacheFactory;
import org.apache.commons.ognl.internal.entry.CacheEntryFactory;
import org.apache.commons.ognl.internal.entry.ClassCacheEntryFactory;
import org.apache.commons.ognl.internal.entry.DeclaredMethodCacheEntry;
import org.apache.commons.ognl.internal.entry.DeclaredMethodCacheEntryFactory;
import org.apache.commons.ognl.internal.entry.FiedlCacheEntryFactory;
import org.apache.commons.ognl.internal.entry.GenericMethodParameterTypeCacheEntry;
import org.apache.commons.ognl.internal.entry.GenericMethodParameterTypeFactory;
import org.apache.commons.ognl.internal.entry.MethodAccessCacheEntryFactory;
import org.apache.commons.ognl.internal.entry.MethodAccessEntryValue;
import org.apache.commons.ognl.internal.entry.MethodPermCacheEntryFactory;
import org.apache.commons.ognl.internal.entry.PermissionCacheEntry;
import org.apache.commons.ognl.internal.entry.PermissionCacheEntryFactory;
import org.apache.commons.ognl.internal.entry.PropertyDescriptorCacheEntryFactory;

import java.beans.BeanInfo;
import java.beans.IndexedPropertyDescriptor;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.MethodDescriptor;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Proxy;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.security.Permission;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Utility class used by internal OGNL API to do various things like:
 * <ul>
 * <li>Handles majority of reflection logic / caching.</li>
 * <li>Utility methods for casting strings / various numeric types used by {@link OgnlExpressionCompiler}.</li.
 * <li>Core runtime configuration point for setting/using global {@link TypeConverter} / {@link OgnlExpressionCompiler}
 * / {@link NullHandler} instances / etc..</li>
 * </ul>
 *
 * @author <NAME> (<EMAIL>)
 * @author <NAME> (<EMAIL>)
 */
public class OgnlRuntime
{

    /**
     * Constant expression used to indicate that a given method / property couldn't be found during reflection
     * operations.
     */
    public static final Object NotFound = new Object( );

    public static final Object[] NoArguments = new Object[]{ };

    public static final Class<?>[] NoArgumentTypes = new Class<?>[]{ };

    /**
     * Token returned by TypeConverter for no conversion possible
     */
    public static final Object NoConversionPossible = "ognl.NoConversionPossible";

    /**
     * Not an indexed property
     */
    public static int INDEXED_PROPERTY_NONE = 0;

    /**
     * JavaBeans IndexedProperty
     */
    public static int INDEXED_PROPERTY_INT = 1;

    /**
     * OGNL ObjectIndexedProperty
     */
    public static int INDEXED_PROPERTY_OBJECT = 2;

    /**
     * Constant string representation of null string.
     */
    public static final String NULL_STRING = "" + null;

    /**
     * Java beans standard set method prefix.
     */
    private static final String SET_PREFIX = "set";

    /**
     * Java beans standard get method prefix.
     */
    private static final String GET_PREFIX = "get";

    /**
     * Java beans standard is<Foo> boolean getter prefix.
     */
    private static final String IS_PREFIX = "is";

    /**
     * Prefix padding for hexadecimal numbers to HEX_LENGTH.
     */
    private static final Map<Integer, String> HEX_PADDING = new HashMap<Integer, String>( );

    private static final int HEX_LENGTH = 8;

    /**
     * Returned by <CODE>getUniqueDescriptor()</CODE> when the object is <CODE>null</CODE>.
     */
    private static final String NULL_OBJECT_STRING = "<null>";

    /**
     * Used to store the result of determining if current jvm is 1.5 language compatible.
     */
    private static boolean _jdk15 = false;

    private static boolean _jdkChecked = false;

    private static CacheFactory cacheFactory = new ConcurrentHashMapCacheFactory( );

    static final ClassCache<MethodAccessor> _methodAccessors = cacheFactory.createClassCache( );

    static final ClassCache<PropertyAccessor> _propertyAccessors = cacheFactory.createClassCache( );

    static final ClassCache<ElementsAccessor> _elementsAccessors = cacheFactory.createClassCache( );

    static final ClassCache<NullHandler> _nullHandlers = cacheFactory.createClassCache( );

    static final ClassCache<Map<String, PropertyDescriptor>> _propertyDescriptorCache =
        cacheFactory.createClassCache( new PropertyDescriptorCacheEntryFactory( ) );

    static final ClassCache<List<Constructor<?>>> _constructorCache =
        cacheFactory.createClassCache( new ClassCacheEntryFactory<List<Constructor<?>>>( )
        {
            public List<Constructor<?>> create( Class<?> key )
                throws CacheException
            {
                return Arrays.asList( key.getConstructors( ) );
            }
        } );

    static final Cache<DeclaredMethodCacheEntry, Map<String, List<Method>>> _methodCache =
        cacheFactory.createCache( new DeclaredMethodCacheEntryFactory( ) );

    static final Cache<PermissionCacheEntry, Permission> _invokePermissionCache =
        cacheFactory.createCache( new PermissionCacheEntryFactory( ) );

    static final ClassCache<Map<String, Field>> _fieldCache =
        cacheFactory.createClassCache( new FiedlCacheEntryFactory( ) );

    static final Map<String, Class<?>> _primitiveTypes = new HashMap<String, Class<?>>( 101 );

    static final Map<Class<?>, Object> _primitiveDefaults = new HashMap<Class<?>, Object>( 20 );

    static final Cache<Method, Class<?>[]> _methodParameterTypesCache =
        cacheFactory.createCache( new CacheEntryFactory<Method, Class<?>[]>( )
        {
            public Class<?>[] create( Method key )
                throws CacheException
            {
                return key.getParameterTypes( );
            }
        } );

    static final Cache<GenericMethodParameterTypeCacheEntry, Class<?>[]> _genericMethodParameterTypesCache =
        cacheFactory.createCache( new GenericMethodParameterTypeFactory( ) );

{'fraction_non_alphanumeric': 0.0951715374841169, 'fraction_numerical': 0.0021601016518424396, 'mean_word_length': 3.9813291139240508, 'pattern_counts': {'":': 0, '<': 119, '<?xml version=': 0, '>': 117, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5391859', 'n_tokens_mistral': 4213, 'n_tokens_neox': 4125, 'n_words': 1153}