ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/java/jakarta/el/StaticFieldELResolver.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/java/jakarta/el/StaticFieldELResolver.java
Status
scanned
Type
file
Name
StaticFieldELResolver.java
Extension
.java
Programming language
Java
Mime type
text/plain
File type
ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
6896 (6.7 KB)
MD5
7d5e8f367a6901fcf0ac5a6d7f0d6c49
SHA1
5484e168e857eb08984e4d84a3c5288751b81fad
SHA256
984b09fe3a8aee774b8f77a68547e361453e802ee628402d248868ad49f63873
SHA512

      
    
SHA1_git
377e7a378aa162c221164c20c7556cfd46bec83e
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
StaticFieldELResolver.java | 6.7 KB |

/* * 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 jakarta.el; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.Objects; /** * @since EL 3.0 */ public class StaticFieldELResolver extends ELResolver { @Override public Object getValue(ELContext context, Object base, Object property) { Objects.requireNonNull(context); if (base instanceof ELClass && property instanceof String name) { context.setPropertyResolved(base, property); Class<?> clazz = ((ELClass) base).getKlass(); Exception exception = null; try { Field field = clazz.getField(name); int modifiers = field.getModifiers(); if (Modifier.isStatic(modifiers) && Modifier.isPublic(modifiers) && Util.canAccess(null, field)) { return field.get(null); } } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) { exception = e; } String msg = Util.message(context, "staticFieldELResolver.notFound", name, clazz.getName()); if (exception == null) { throw new PropertyNotFoundException(msg); } else { throw new PropertyNotFoundException(msg, exception); } } return null; } @Override public void setValue(ELContext context, Object base, Object property, Object value) { Objects.requireNonNull(context); if (base instanceof ELClass && property instanceof String name) { Class<?> clazz = ((ELClass) base).getKlass(); throw new PropertyNotWritableException( Util.message(context, "staticFieldELResolver.notWritable", name, clazz.getName())); } } @Override public Object invoke(ELContext context, Object base, Object method, Class<?>[] paramTypes, Object[] params) { Objects.requireNonNull(context); if (base instanceof ELClass && method instanceof String methodName) { context.setPropertyResolved(base, method); Class<?> clazz = ((ELClass) base).getKlass(); if ("<init>".equals(methodName)) { Constructor<?> match = Util.findConstructor(context, clazz, paramTypes, params); Object[] parameters = Util.buildParameters(context, match.getParameterTypes(), match.isVarArgs(), params); Object result; try { result = match.newInstance(parameters); } catch (InvocationTargetException e) { Throwable cause = e.getCause(); Util.handleThrowable(cause); throw new ELException(cause); } catch (ReflectiveOperationException e) { throw new ELException(e); } return result; } else { // Static method so base should be null Method match = Util.findMethod(context, clazz, null, methodName, paramTypes, params); if (match == null) { throw new MethodNotFoundException( Util.message(context, "staticFieldELResolver.methodNotFound", methodName, clazz.getName())); } Object[] parameters = Util.buildParameters(context, match.getParameterTypes(), match.isVarArgs(), params); Object result; try { result = match.invoke(null, parameters); } catch (IllegalArgumentException | IllegalAccessException e) { throw new ELException(e); } catch (InvocationTargetException e) { Throwable cause = e.getCause(); Util.handleThrowable(cause); throw new ELException(cause); } return result; } } return null; } @Override public Class<?> getType(ELContext context, Object base, Object property) { Objects.requireNonNull(context); if (base instanceof ELClass && property instanceof String name) { context.setPropertyResolved(base, property); Class<?> clazz = ((ELClass) base).getKlass(); Exception exception = null; try { Field field = clazz.getField(name); int modifiers = field.getModifiers(); if (Modifier.isStatic(modifiers) && Modifier.isPublic(modifiers) && Util.canAccess(null, field)) { // Resolver is read-only so returns null for resolved fields return null; } } catch (IllegalArgumentException | NoSuchFieldException | SecurityException e) { exception = e; } String msg = Util.message(context, "staticFieldELResolver.notFound", name, clazz.getName()); if (exception == null) { throw new PropertyNotFoundException(msg); } else { throw new PropertyNotFoundException(msg, exception); } } return null; } @Override public boolean isReadOnly(ELContext context, Object base, Object property) { Objects.requireNonNull(context); if (base instanceof ELClass && property instanceof String) { context.setPropertyResolved(base, property); } return true; } /** * @return This resolver always returns <code>String.class</code> */ @Override public Class<?> getCommonPropertyType(ELContext context, Object base) { return String.class; } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
20.31
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9