Java Code Examples for java.lang.invoke.SerializedLambda

The following examples show how to use java.lang.invoke.SerializedLambda. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public ObjectInputFilter.Status checkInput(FilterInfo filter) {
    Class<?> serialClass = filter.serialClass();
    System.out.printf("     checkInput: class: %s, arrayLen: %d, refs: %d, depth: %d, bytes; %d%n",
            serialClass, filter.arrayLength(), filter.references(),
            filter.depth(), filter.streamBytes());
    count++;
    if (serialClass != null) {
        if (serialClass.getName().contains("$$Lambda$")) {
            // TBD: proper identification of serialized Lambdas?
            // Fold the serialized Lambda into the SerializedLambda type
            classes.add(SerializedLambda.class);
        } else if (Proxy.isProxyClass(serialClass)) {
            classes.add(Proxy.class);
        } else {
            classes.add(serialClass);
        }

    }
    this.maxArray = Math.max(this.maxArray, filter.arrayLength());
    this.maxRefs = Math.max(this.maxRefs, filter.references());
    this.maxDepth = Math.max(this.maxDepth, filter.depth());
    this.maxBytes = Math.max(this.maxBytes, filter.streamBytes());
    return ObjectInputFilter.Status.UNDECIDED;
}
 
Example 2
@Override
public ObjectInputFilter.Status checkInput(FilterInfo filter) {
    Class<?> serialClass = filter.serialClass();
    System.out.printf("     checkInput: class: %s, arrayLen: %d, refs: %d, depth: %d, bytes; %d%n",
            serialClass, filter.arrayLength(), filter.references(),
            filter.depth(), filter.streamBytes());
    count++;
    if (serialClass != null) {
        if (serialClass.getName().contains("$$Lambda$")) {
            // TBD: proper identification of serialized Lambdas?
            // Fold the serialized Lambda into the SerializedLambda type
            classes.add(SerializedLambda.class);
        } else if (Proxy.isProxyClass(serialClass)) {
            classes.add(Proxy.class);
        } else {
            classes.add(serialClass);
        }

    }
    this.maxArray = Math.max(this.maxArray, filter.arrayLength());
    this.maxRefs = Math.max(this.maxRefs, filter.references());
    this.maxDepth = Math.max(this.maxDepth, filter.depth());
    this.maxBytes = Math.max(this.maxBytes, filter.streamBytes());
    return ObjectInputFilter.Status.UNDECIDED;
}
 
Example 3
Source Project: summerframework   Source File: MyBatisUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static <T> String getFieldName(EntityGetterMethod<T, Object> expression) {
    if (expression == null)
        throw new IllegalArgumentException("Expression should not be null");
    try {
        Method method = expression.getClass().getDeclaredMethod("writeReplace");
        method.setAccessible(Boolean.TRUE);
        SerializedLambda serializedLambda = (SerializedLambda)method.invoke(expression);
        String fieldName = StringUtils.resolveFieldName(serializedLambda.getImplMethodName());
        String className = serializedLambda.getImplClass().replace("/", ".");
        Field field = ReflectionUtils.findField(Class.forName(className), fieldName);
        String columnName = field.getName();
        TableField[] tableField = field.getAnnotationsByType(TableField.class);
        if (null != tableField && tableField.length == 1) {
            if (!StringUtils.isEmpty(tableField[0].value())) {
                columnName = tableField[0].value();
            }
        }
        String ret = StringUtils.camelToUnderline(columnName);
        return ret;
    } catch (ReflectiveOperationException e) {
        throw new RuntimeException("This will never happen!", e);
    }
}
 
Example 4
@Override
public ObjectInputFilter.Status checkInput(FilterInfo filter) {
    Class<?> serialClass = filter.serialClass();
    System.out.printf("     checkInput: class: %s, arrayLen: %d, refs: %d, depth: %d, bytes; %d%n",
            serialClass, filter.arrayLength(), filter.references(),
            filter.depth(), filter.streamBytes());
    count++;
    if (serialClass != null) {
        if (serialClass.getName().contains("$$Lambda$")) {
            // TBD: proper identification of serialized Lambdas?
            // Fold the serialized Lambda into the SerializedLambda type
            classes.add(SerializedLambda.class);
        } else if (Proxy.isProxyClass(serialClass)) {
            classes.add(Proxy.class);
        } else {
            classes.add(serialClass);
        }

    }
    this.maxArray = Math.max(this.maxArray, filter.arrayLength());
    this.maxRefs = Math.max(this.maxRefs, filter.references());
    this.maxDepth = Math.max(this.maxDepth, filter.depth());
    this.maxBytes = Math.max(this.maxBytes, filter.streamBytes());
    return ObjectInputFilter.Status.UNDECIDED;
}
 
Example 5
@Override
public ObjectInputFilter.Status checkInput(FilterInfo filter) {
    Class<?> serialClass = filter.serialClass();
    System.out.printf("     checkInput: class: %s, arrayLen: %d, refs: %d, depth: %d, bytes; %d%n",
            serialClass, filter.arrayLength(), filter.references(),
            filter.depth(), filter.streamBytes());
    count++;
    if (serialClass != null) {
        if (serialClass.getName().contains("$$Lambda$")) {
            // TBD: proper identification of serialized Lambdas?
            // Fold the serialized Lambda into the SerializedLambda type
            classes.add(SerializedLambda.class);
        } else if (Proxy.isProxyClass(serialClass)) {
            classes.add(Proxy.class);
        } else {
            classes.add(serialClass);
        }

    }
    this.maxArray = Math.max(this.maxArray, filter.arrayLength());
    this.maxRefs = Math.max(this.maxRefs, filter.references());
    this.maxDepth = Math.max(this.maxDepth, filter.depth());
    this.maxBytes = Math.max(this.maxBytes, filter.streamBytes());
    return ObjectInputFilter.Status.UNDECIDED;
}
 
Example 6
@Override
public ObjectInputFilter.Status checkInput(FilterInfo filter) {
    Class<?> serialClass = filter.serialClass();
    System.out.printf("     checkInput: class: %s, arrayLen: %d, refs: %d, depth: %d, bytes; %d%n",
            serialClass, filter.arrayLength(), filter.references(),
            filter.depth(), filter.streamBytes());
    count++;
    if (serialClass != null) {
        if (serialClass.getName().contains("$$Lambda$")) {
            // TBD: proper identification of serialized Lambdas?
            // Fold the serialized Lambda into the SerializedLambda type
            classes.add(SerializedLambda.class);
        } else if (Proxy.isProxyClass(serialClass)) {
            classes.add(Proxy.class);
        } else {
            classes.add(serialClass);
        }

    }
    this.maxArray = Math.max(this.maxArray, filter.arrayLength());
    this.maxRefs = Math.max(this.maxRefs, filter.references());
    this.maxDepth = Math.max(this.maxDepth, filter.depth());
    this.maxBytes = Math.max(this.maxBytes, filter.streamBytes());
    return ObjectInputFilter.Status.UNDECIDED;
}
 
Example 7
Source Project: jdk8u-jdk   Source File: SerialFilterTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public ObjectInputFilter.Status checkInput(FilterInfo filter) {
    count++;
    if (filter.serialClass() != null) {
        if (filter.serialClass().getName().contains("$$Lambda$")) {
            // TBD: proper identification of serialized Lambdas?
            // Fold the serialized Lambda into the SerializedLambda type
            classes.add(SerializedLambda.class);
        } else if (Proxy.isProxyClass(filter.serialClass())) {
            classes.add(Proxy.class);
        } else {
            classes.add(filter.serialClass());
        }

    }
    this.maxArray = Math.max(this.maxArray, filter.arrayLength());
    this.maxRefs = Math.max(this.maxRefs, filter.references());
    this.maxDepth = Math.max(this.maxDepth, filter.depth());
    this.maxBytes = Math.max(this.maxBytes, filter.streamBytes());
    return ObjectInputFilter.Status.UNDECIDED;
}
 
Example 8
Source Project: jdk8u_jdk   Source File: SerialFilterTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public ObjectInputFilter.Status checkInput(FilterInfo filter) {
    Class<?> serialClass = filter.serialClass();
    System.out.printf("     checkInput: class: %s, arrayLen: %d, refs: %d, depth: %d, bytes; %d%n",
            serialClass, filter.arrayLength(), filter.references(),
            filter.depth(), filter.streamBytes());
    count++;
    if (serialClass != null) {
        if (serialClass.getName().contains("$$Lambda$")) {
            // TBD: proper identification of serialized Lambdas?
            // Fold the serialized Lambda into the SerializedLambda type
            classes.add(SerializedLambda.class);
        } else if (Proxy.isProxyClass(serialClass)) {
            classes.add(Proxy.class);
        } else {
            classes.add(serialClass);
        }

    }
    this.maxArray = Math.max(this.maxArray, filter.arrayLength());
    this.maxRefs = Math.max(this.maxRefs, filter.references());
    this.maxDepth = Math.max(this.maxDepth, filter.depth());
    this.maxBytes = Math.max(this.maxBytes, filter.streamBytes());
    return ObjectInputFilter.Status.UNDECIDED;
}
 
Example 9
private static String[] getSerializedLambdaParameterizedTypeNames(Object source) {
	Method method = ReflectionUtils.findMethod(source.getClass(), "writeReplace");
	if (method == null) {
		return null;
	}
	ReflectionUtils.makeAccessible(method);
	SerializedLambda serializedLambda = (SerializedLambda) ReflectionUtils
			.invokeMethod(method, source);
	String signature = serializedLambda.getImplMethodSignature().replaceAll("[()]",
			"");

	List<String> typeNames = Stream.of(signature.split(";"))
			.map(t -> t.substring(1).replace('/', '.')).collect(Collectors.toList());

	return typeNames.toArray(new String[typeNames.size()]);
}
 
Example 10
Source Project: weed3   Source File: PropertyWrap.java    License: Apache License 2.0 6 votes vote down vote up
/** 将 Property 转为 PropertyWrap  */
private static <C> PropertyWrap wrap(Property<C, ?> p) {
    try {
        Method fun = p.getClass().getDeclaredMethod("writeReplace");
        fun.setAccessible(Boolean.TRUE);
        SerializedLambda slambda = (SerializedLambda) fun.invoke(p);
        String method = slambda.getImplMethodName();
        String attr = null;
        if (method.startsWith("get")) {
            attr = method.substring(3);
        } else {
            attr = method.substring(2);//is
        }
        return new PropertyWrap(p, slambda.getImplClass(), attr);
    } catch (ReflectiveOperationException e) {
        throw new RuntimeException(e);
    }
}
 
Example 11
Source Project: weed3   Source File: PropertyTest.java    License: Apache License 2.0 6 votes vote down vote up
private static  <C> String getName(Property<C, ?> property) {
    try {
        Method declaredMethod = property.getClass().getDeclaredMethod("writeReplace");
        declaredMethod.setAccessible(Boolean.TRUE);
        SerializedLambda serializedLambda = (SerializedLambda) declaredMethod.invoke(property);
        String method = serializedLambda.getImplMethodName();
        String attr = null;
        if (method.startsWith("get")) {
            attr = method.substring(3);
        } else {
            attr = method.substring(2);
        }
        return attr;
    } catch (ReflectiveOperationException e) {
        throw new RuntimeException(e);
    }
}
 
Example 12
Source Project: blade   Source File: BladeCache.java    License: Apache License 2.0 6 votes vote down vote up
public static String getLambdaFieldName(SerializedLambda serializedLambda) {
    String name = CACHE_LAMBDA_NAME.get(serializedLambda);
    if (null != name) {
        return name;
    }
    String className  = serializedLambda.getImplClass().replace("/", ".");
    String methodName = serializedLambda.getImplMethodName();
    String fieldName  = methodToFieldName(methodName);
    try {
        Field field = Class.forName(className).getDeclaredField(fieldName);
        name = field.getName();
        CACHE_LAMBDA_NAME.put(serializedLambda, name);
        return name;
    } catch (NoSuchFieldException | ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
}
 
Example 13
Source Project: Mapper   Source File: Reflections.java    License: MIT License 6 votes vote down vote up
public static String fnToFieldName(Fn fn) {
    try {
        Method method = fn.getClass().getDeclaredMethod("writeReplace");
        method.setAccessible(Boolean.TRUE);
        SerializedLambda serializedLambda = (SerializedLambda) method.invoke(fn);
        String getter = serializedLambda.getImplMethodName();
        if (GET_PATTERN.matcher(getter).matches()) {
            getter = getter.substring(3);
        } else if (IS_PATTERN.matcher(getter).matches()) {
            getter = getter.substring(2);
        }
        return Introspector.decapitalize(getter);
    } catch (ReflectiveOperationException e) {
        throw new ReflectionOperationException(e);
    }
}
 
Example 14
private void assertDeserializeMethod(Class<?> clazz, boolean expectedPresent) {
    try {
        Method m = clazz.getDeclaredMethod("$deserializeLambda$", SerializedLambda.class);
        if (!expectedPresent)
            fail("Unexpected $deserializeLambda$ in " + clazz);
    }
    catch (NoSuchMethodException e) {
        if (expectedPresent)
            fail("Expected to find $deserializeLambda$ in " + clazz);
    }
}
 
Example 15
private void assertDeserializeMethod(Class<?> clazz, boolean expectedPresent) {
    try {
        Method m = clazz.getDeclaredMethod("$deserializeLambda$", SerializedLambda.class);
        if (!expectedPresent)
            fail("Unexpected $deserializeLambda$ in " + clazz);
    }
    catch (NoSuchMethodException e) {
        if (expectedPresent)
            fail("Expected to find $deserializeLambda$ in " + clazz);
    }
}
 
Example 16
Source Project: summerframework   Source File: ExpressionUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static String expressionToMethodName(Expression expression) {
    if (expression == null)
        return "";
    try {
        Method method = expression.getClass().getDeclaredMethod("writeReplace");
        method.setAccessible(Boolean.TRUE);
        SerializedLambda serializedLambda = (SerializedLambda)method.invoke(expression);
        return serializedLambda.getImplMethodName();
    } catch (ReflectiveOperationException e) {
        return "";
    }
}
 
Example 17
private void assertDeserializeMethod(Class<?> clazz, boolean expectedPresent) {
    try {
        Method m = clazz.getDeclaredMethod("$deserializeLambda$", SerializedLambda.class);
        if (!expectedPresent)
            fail("Unexpected $deserializeLambda$ in " + clazz);
    }
    catch (NoSuchMethodException e) {
        if (expectedPresent)
            fail("Expected to find $deserializeLambda$ in " + clazz);
    }
}
 
Example 18
Source Project: GyJdbc   Source File: TypeFunction.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 获取列名称
 * @param lambda lamda表达式
 * @return String 列名称
 */
static String getLambdaColumnName(Serializable lambda) {
    try {
        Method method = lambda.getClass().getDeclaredMethod("writeReplace");
        method.setAccessible(Boolean.TRUE);
        SerializedLambda serializedLambda = (SerializedLambda) method.invoke(lambda);
        String getter = serializedLambda.getImplMethodName();
        String fieldName = Introspector.decapitalize(getter.replace("get", ""));
        return EntityTools.transferColumnName(fieldName);
    } catch (ReflectiveOperationException e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example 19
private void assertDeserializeMethod(Class<?> clazz, boolean expectedPresent) {
    try {
        Method m = clazz.getDeclaredMethod("$deserializeLambda$", SerializedLambda.class);
        if (!expectedPresent)
            fail("Unexpected $deserializeLambda$ in " + clazz);
    }
    catch (NoSuchMethodException e) {
        if (expectedPresent)
            fail("Expected to find $deserializeLambda$ in " + clazz);
    }
}
 
Example 20
Source Project: redpipe   Source File: MethodFinder.java    License: Apache License 2.0 5 votes vote down vote up
default SerializedLambda serialized() {
    try {
        Method replaceMethod = getClass().getDeclaredMethod("writeReplace");
        replaceMethod.setAccessible(true);
        return (SerializedLambda) replaceMethod.invoke(this);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 21
Source Project: redpipe   Source File: MethodFinder.java    License: Apache License 2.0 5 votes vote down vote up
default Method method() {
    SerializedLambda lambda = serialized();
    Class<?> containingClass = getContainingClass();
    return Arrays.asList(containingClass.getDeclaredMethods())
            .stream()
            .filter(method -> Objects.equals(method.getName(), lambda.getImplMethodName()))
            .findFirst()
            .orElseThrow(UnableToGuessMethodException::new);
}
 
Example 22
Source Project: vertx-sql-client   Source File: ColumnChecker.java    License: Apache License 2.0 5 votes vote down vote up
default SerializedLambda serialized() {
  try {
    Method replaceMethod = getClass().getDeclaredMethod("writeReplace");
    replaceMethod.setAccessible(true);
    return (SerializedLambda) replaceMethod.invoke(this);
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example 23
Source Project: vertx-sql-client   Source File: ColumnChecker.java    License: Apache License 2.0 5 votes vote down vote up
default Method method() {
  SerializedLambda lambda = serialized();
  Class containingClass = getContainingClass();
  return Arrays.stream(containingClass.getDeclaredMethods())
    .filter(method -> Objects.equals(method.getName(), lambda.getImplMethodName()))
    .findFirst()
    .orElseThrow(MethodReferenceReflection.UnableToGuessMethodException::new);
}
 
Example 24
private void assertDeserializeMethod(Class<?> clazz, boolean expectedPresent) {
    try {
        Method m = clazz.getDeclaredMethod("$deserializeLambda$", SerializedLambda.class);
        if (!expectedPresent)
            fail("Unexpected $deserializeLambda$ in " + clazz);
    }
    catch (NoSuchMethodException e) {
        if (expectedPresent)
            fail("Expected to find $deserializeLambda$ in " + clazz);
    }
}
 
Example 25
private void assertDeserializeMethod(Class<?> clazz, boolean expectedPresent) {
    try {
        Method m = clazz.getDeclaredMethod("$deserializeLambda$", SerializedLambda.class);
        if (!expectedPresent)
            fail("Unexpected $deserializeLambda$ in " + clazz);
    }
    catch (NoSuchMethodException e) {
        if (expectedPresent)
            fail("Expected to find $deserializeLambda$ in " + clazz);
    }
}
 
Example 26
private void assertDeserializeMethod(Class<?> clazz, boolean expectedPresent) {
    try {
        Method m = clazz.getDeclaredMethod("$deserializeLambda$", SerializedLambda.class);
        if (!expectedPresent)
            fail("Unexpected $deserializeLambda$ in " + clazz);
    }
    catch (NoSuchMethodException e) {
        if (expectedPresent)
            fail("Expected to find $deserializeLambda$ in " + clazz);
    }
}
 
Example 27
Source Project: mybatis-dynamic-query   Source File: CommonsHelper.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("squid:S00112")
public static <T, R extends Comparable> PropertyInfo getPropertyInfo(GetPropertyFunction<T, R> fn) {
    try {
        Method method = fn.getClass().getDeclaredMethod("writeReplace");
        method.setAccessible(true);
        SerializedLambda serializedLambda = (SerializedLambda) method.invoke(fn);
        String methodName = serializedLambda.getImplMethodName();
        String className = serializedLambda.getImplClass();
        String propertyName;
        String getString = "get";
        String isString = "is";
        if (methodName.startsWith(getString)) {
            propertyName = java.beans.Introspector.decapitalize(methodName.substring(3));
        } else if (methodName.startsWith(isString)) {
            propertyName = java.beans.Introspector.decapitalize(methodName.substring(2));
        } else {
            propertyName = methodName;
        }

        Class ownerClass;
        if (classMap.containsKey(className)) {
            ownerClass = classMap.get(className);
        } else {
            ownerClass = Class.forName(className.replace('/', '.'));
            classMap.put(className, ownerClass);
        }

        PropertyInfo propertyInfo = new PropertyInfo();
        propertyInfo.setPropertyName(propertyName);
        propertyInfo.setOwnerClass(ownerClass);
        return propertyInfo;
    } catch (ReflectiveOperationException e) {
        throw new InternalRuntimeException(e);
    }
}
 
Example 28
Source Project: hottub   Source File: DeserializeMethodTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void assertDeserializeMethod(Class<?> clazz, boolean expectedPresent) {
    try {
        Method m = clazz.getDeclaredMethod("$deserializeLambda$", SerializedLambda.class);
        if (!expectedPresent)
            fail("Unexpected $deserializeLambda$ in " + clazz);
    }
    catch (NoSuchMethodException e) {
        if (expectedPresent)
            fail("Expected to find $deserializeLambda$ in " + clazz);
    }
}
 
Example 29
private void assertDeserializeMethod(Class<?> clazz, boolean expectedPresent) {
    try {
        Method m = clazz.getDeclaredMethod("$deserializeLambda$", SerializedLambda.class);
        if (!expectedPresent)
            fail("Unexpected $deserializeLambda$ in " + clazz);
    }
    catch (NoSuchMethodException e) {
        if (expectedPresent)
            fail("Expected to find $deserializeLambda$ in " + clazz);
    }
}
 
Example 30
private void assertDeserializeMethod(Class<?> clazz, boolean expectedPresent) {
    try {
        Method m = clazz.getDeclaredMethod("$deserializeLambda$", SerializedLambda.class);
        if (!expectedPresent)
            fail("Unexpected $deserializeLambda$ in " + clazz);
    }
    catch (NoSuchMethodException e) {
        if (expectedPresent)
            fail("Expected to find $deserializeLambda$ in " + clazz);
    }
}