Skip to content

Commit

Permalink
8222799: java.beans.Introspector uses an obsolete methods cache
Browse files Browse the repository at this point in the history
Reviewed-by: mdoerr
Backport-of: 921b467
  • Loading branch information
basil authored and TheRealMDoerr committed May 25, 2022
1 parent d71a543 commit 69bdf9b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 37 deletions.
45 changes: 13 additions & 32 deletions src/java.desktop/share/classes/java/beans/Introspector.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -22,33 +22,29 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.beans;

import com.sun.beans.TypeResolver;
import com.sun.beans.WeakCache;
import com.sun.beans.finder.ClassFinder;
import com.sun.beans.introspect.ClassInfo;
import com.sun.beans.introspect.EventSetInfo;
import com.sun.beans.introspect.PropertyInfo;
package java.beans;

import java.awt.Component;

import java.lang.ref.Reference;
import java.lang.ref.SoftReference;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Type;

import java.util.Map;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EventObject;
import java.util.HashMap;
import java.util.Iterator;
import java.util.EventObject;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import com.sun.beans.TypeResolver;
import com.sun.beans.finder.ClassFinder;
import com.sun.beans.introspect.ClassInfo;
import com.sun.beans.introspect.EventSetInfo;
import com.sun.beans.introspect.PropertyInfo;
import jdk.internal.misc.JavaBeansAccess;
import jdk.internal.misc.SharedSecrets;
import sun.reflect.misc.ReflectUtil;
Expand Down Expand Up @@ -115,9 +111,6 @@ public class Introspector {
*/
public static final int IGNORE_ALL_BEANINFO = 3;

// Static Caches to speed up introspection.
private static final WeakCache<Class<?>, Method[]> declaredMethodCache = new WeakCache<>();

private Class<?> beanClass;
private BeanInfo explicitBeanInfo;
private BeanInfo superBeanInfo;
Expand Down Expand Up @@ -197,15 +190,10 @@ public static BeanInfo getBeanInfo(Class<?> beanClass)
return (new Introspector(beanClass, null, USE_ALL_BEANINFO)).getBeanInfo();
}
ThreadGroupContext context = ThreadGroupContext.getContext();
BeanInfo beanInfo;
synchronized (declaredMethodCache) {
beanInfo = context.getBeanInfo(beanClass);
}
BeanInfo beanInfo = context.getBeanInfo(beanClass);
if (beanInfo == null) {
beanInfo = new Introspector(beanClass, null, USE_ALL_BEANINFO).getBeanInfo();
synchronized (declaredMethodCache) {
context.putBeanInfo(beanClass, beanInfo);
}
context.putBeanInfo(beanClass, beanInfo);
}
return beanInfo;
}
Expand Down Expand Up @@ -374,12 +362,8 @@ public static void setBeanInfoSearchPath(String[] path) {
*
* @since 1.2
*/

public static void flushCaches() {
synchronized (declaredMethodCache) {
ThreadGroupContext.getContext().clearBeanInfoCache();
declaredMethodCache.clear();
}
ThreadGroupContext.getContext().clearBeanInfoCache();
}

/**
Expand All @@ -402,10 +386,7 @@ public static void flushFromCaches(Class<?> clz) {
if (clz == null) {
throw new NullPointerException();
}
synchronized (declaredMethodCache) {
ThreadGroupContext.getContext().removeBeanInfo(clz);
declaredMethodCache.put(clz, null);
}
ThreadGroupContext.getContext().removeBeanInfo(clz);
}

//======================================================================
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -88,26 +88,26 @@ void setGuiAvailable(boolean isGuiAvailable) {
}


BeanInfo getBeanInfo(Class<?> type) {
synchronized BeanInfo getBeanInfo(Class<?> type) {
return (this.beanInfoCache != null)
? this.beanInfoCache.get(type)
: null;
}

BeanInfo putBeanInfo(Class<?> type, BeanInfo info) {
synchronized BeanInfo putBeanInfo(Class<?> type, BeanInfo info) {
if (this.beanInfoCache == null) {
this.beanInfoCache = new WeakHashMap<>();
}
return this.beanInfoCache.put(type, info);
}

void removeBeanInfo(Class<?> type) {
synchronized void removeBeanInfo(Class<?> type) {
if (this.beanInfoCache != null) {
this.beanInfoCache.remove(type);
}
}

void clearBeanInfoCache() {
synchronized void clearBeanInfoCache() {
if (this.beanInfoCache != null) {
this.beanInfoCache.clear();
}
Expand Down

1 comment on commit 69bdf9b

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.