src/java.base/share/classes/sun/reflect/generics/repository/GenericDeclRepository.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2014, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -40,11 +40,11 @@
* It is designed to be used unchanged by at least core reflection and JDI.
*/
public abstract class GenericDeclRepository<S extends Signature>
extends AbstractRepository<S> {
- private TypeVariable<?>[] typeParams; // caches the formal type parameters
+ private volatile TypeVariable<?>[] typeParams; // caches the formal type parameters
protected GenericDeclRepository(String rawSig, GenericsFactory f) {
super(rawSig, f);
}
@@ -63,22 +63,23 @@
/**
* Return the formal type parameters of this generic declaration.
* @return the formal type parameters of this generic declaration
*/
public TypeVariable<?>[] getTypeParameters(){
- if (typeParams == null) { // lazily initialize type parameters
+ TypeVariable<?>[] tps = typeParams;
+ if (tps == null) { // lazily initialize type parameters
// first, extract type parameter subtree(s) from AST
FormalTypeParameter[] ftps = getTree().getFormalTypeParameters();
// create array to store reified subtree(s)
- TypeVariable<?>[] tps = new TypeVariable<?>[ftps.length];
+ tps = new TypeVariable<?>[ftps.length];
// reify all subtrees
for (int i = 0; i < ftps.length; i++) {
Reifier r = getReifier(); // obtain visitor
ftps[i].accept(r); // reify subtree
// extract result from visitor and store it
tps[i] = (TypeVariable<?>) r.getResult();
}
typeParams = tps; // cache overall result
}
- return typeParams.clone(); // return cached result
+ return tps.clone(); // return cached result
}
}