Skip to content

Commit 69bdf9b

Browse files
basilTheRealMDoerr
authored andcommitted
8222799: java.beans.Introspector uses an obsolete methods cache
Reviewed-by: mdoerr Backport-of: 921b467
1 parent d71a543 commit 69bdf9b

File tree

2 files changed

+18
-37
lines changed

2 files changed

+18
-37
lines changed

src/java.desktop/share/classes/java/beans/Introspector.java

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -22,33 +22,29 @@
2222
* or visit www.oracle.com if you need additional information or have any
2323
* questions.
2424
*/
25-
package java.beans;
2625

27-
import com.sun.beans.TypeResolver;
28-
import com.sun.beans.WeakCache;
29-
import com.sun.beans.finder.ClassFinder;
30-
import com.sun.beans.introspect.ClassInfo;
31-
import com.sun.beans.introspect.EventSetInfo;
32-
import com.sun.beans.introspect.PropertyInfo;
26+
package java.beans;
3327

3428
import java.awt.Component;
35-
3629
import java.lang.ref.Reference;
3730
import java.lang.ref.SoftReference;
3831
import java.lang.reflect.Constructor;
3932
import java.lang.reflect.InvocationTargetException;
4033
import java.lang.reflect.Method;
4134
import java.lang.reflect.Type;
42-
43-
import java.util.Map;
4435
import java.util.ArrayList;
45-
import java.util.Arrays;
36+
import java.util.EventObject;
4637
import java.util.HashMap;
4738
import java.util.Iterator;
48-
import java.util.EventObject;
4939
import java.util.List;
40+
import java.util.Map;
5041
import java.util.TreeMap;
5142

43+
import com.sun.beans.TypeResolver;
44+
import com.sun.beans.finder.ClassFinder;
45+
import com.sun.beans.introspect.ClassInfo;
46+
import com.sun.beans.introspect.EventSetInfo;
47+
import com.sun.beans.introspect.PropertyInfo;
5248
import jdk.internal.misc.JavaBeansAccess;
5349
import jdk.internal.misc.SharedSecrets;
5450
import sun.reflect.misc.ReflectUtil;
@@ -115,9 +111,6 @@ public class Introspector {
115111
*/
116112
public static final int IGNORE_ALL_BEANINFO = 3;
117113

118-
// Static Caches to speed up introspection.
119-
private static final WeakCache<Class<?>, Method[]> declaredMethodCache = new WeakCache<>();
120-
121114
private Class<?> beanClass;
122115
private BeanInfo explicitBeanInfo;
123116
private BeanInfo superBeanInfo;
@@ -197,15 +190,10 @@ public static BeanInfo getBeanInfo(Class<?> beanClass)
197190
return (new Introspector(beanClass, null, USE_ALL_BEANINFO)).getBeanInfo();
198191
}
199192
ThreadGroupContext context = ThreadGroupContext.getContext();
200-
BeanInfo beanInfo;
201-
synchronized (declaredMethodCache) {
202-
beanInfo = context.getBeanInfo(beanClass);
203-
}
193+
BeanInfo beanInfo = context.getBeanInfo(beanClass);
204194
if (beanInfo == null) {
205195
beanInfo = new Introspector(beanClass, null, USE_ALL_BEANINFO).getBeanInfo();
206-
synchronized (declaredMethodCache) {
207-
context.putBeanInfo(beanClass, beanInfo);
208-
}
196+
context.putBeanInfo(beanClass, beanInfo);
209197
}
210198
return beanInfo;
211199
}
@@ -374,12 +362,8 @@ public static void setBeanInfoSearchPath(String[] path) {
374362
*
375363
* @since 1.2
376364
*/
377-
378365
public static void flushCaches() {
379-
synchronized (declaredMethodCache) {
380-
ThreadGroupContext.getContext().clearBeanInfoCache();
381-
declaredMethodCache.clear();
382-
}
366+
ThreadGroupContext.getContext().clearBeanInfoCache();
383367
}
384368

385369
/**
@@ -402,10 +386,7 @@ public static void flushFromCaches(Class<?> clz) {
402386
if (clz == null) {
403387
throw new NullPointerException();
404388
}
405-
synchronized (declaredMethodCache) {
406-
ThreadGroupContext.getContext().removeBeanInfo(clz);
407-
declaredMethodCache.put(clz, null);
408-
}
389+
ThreadGroupContext.getContext().removeBeanInfo(clz);
409390
}
410391

411392
//======================================================================

src/java.desktop/share/classes/java/beans/ThreadGroupContext.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -88,26 +88,26 @@ void setGuiAvailable(boolean isGuiAvailable) {
8888
}
8989

9090

91-
BeanInfo getBeanInfo(Class<?> type) {
91+
synchronized BeanInfo getBeanInfo(Class<?> type) {
9292
return (this.beanInfoCache != null)
9393
? this.beanInfoCache.get(type)
9494
: null;
9595
}
9696

97-
BeanInfo putBeanInfo(Class<?> type, BeanInfo info) {
97+
synchronized BeanInfo putBeanInfo(Class<?> type, BeanInfo info) {
9898
if (this.beanInfoCache == null) {
9999
this.beanInfoCache = new WeakHashMap<>();
100100
}
101101
return this.beanInfoCache.put(type, info);
102102
}
103103

104-
void removeBeanInfo(Class<?> type) {
104+
synchronized void removeBeanInfo(Class<?> type) {
105105
if (this.beanInfoCache != null) {
106106
this.beanInfoCache.remove(type);
107107
}
108108
}
109109

110-
void clearBeanInfoCache() {
110+
synchronized void clearBeanInfoCache() {
111111
if (this.beanInfoCache != null) {
112112
this.beanInfoCache.clear();
113113
}

0 commit comments

Comments
 (0)