src/java.base/share/classes/sun/reflect/generics/repository/ConstructorRepository.java
Print this page
@@ -41,12 +41,12 @@
* It is designed to be used unchanged by at least core reflection and JDI.
*/
public class ConstructorRepository
extends GenericDeclRepository<MethodTypeSignature> {
- private Type[] paramTypes; // caches the generic parameter types info
- private Type[] exceptionTypes; // caches the generic exception types info
+ private volatile Type[] paramTypes; // caches the generic parameter types info
+ private volatile Type[] exceptionTypes; // caches the generic exception types info
// protected, to enforce use of static factory yet allow subclassing
protected ConstructorRepository(String rawSig, GenericsFactory f) {
super(rawSig, f);
}
@@ -81,40 +81,42 @@
* a visitor, which is created by feeding it the factory
* with which the repository was created.
*/
public Type[] getParameterTypes(){
- if (paramTypes == null) { // lazily initialize parameter types
+ Type[] ps = paramTypes;
+ if (ps == null) { // lazily initialize parameter types
// first, extract parameter type subtree(s) from AST
TypeSignature[] pts = getTree().getParameterTypes();
// create array to store reified subtree(s)
- Type[] ps = new Type[pts.length];
+ ps = new Type[pts.length];
// reify all subtrees
for (int i = 0; i < pts.length; i++) {
Reifier r = getReifier(); // obtain visitor
pts[i].accept(r); // reify subtree
// extract result from visitor and store it
ps[i] = r.getResult();
}
paramTypes = ps; // cache overall result
}
- return paramTypes.clone(); // return cached result
+ return ps.clone(); // return cached result
}
public Type[] getExceptionTypes(){
- if (exceptionTypes == null) { // lazily initialize exception types
+ Type[] es = exceptionTypes;
+ if (es == null) { // lazily initialize exception types
// first, extract exception type subtree(s) from AST
FieldTypeSignature[] ets = getTree().getExceptionTypes();
// create array to store reified subtree(s)
- Type[] es = new Type[ets.length];
+ es = new Type[ets.length];
// reify all subtrees
for (int i = 0; i < ets.length; i++) {
Reifier r = getReifier(); // obtain visitor
ets[i].accept(r); // reify subtree
// extract result from visitor and store it
es[i] = r.getResult();
}
exceptionTypes = es; // cache overall result
}
- return exceptionTypes.clone(); // return cached result
+ return es.clone(); // return cached result
}
}