8231587: Memory leak in WorkArounds.serializedForms
Reviewed-by: hannesw
Contributed-by: fw@deneb.enyo.de
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/WorkArounds.java Mon Oct 21 11:35:36 2019 -0700
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/WorkArounds.java Mon Oct 21 13:25:36 2019 -0700
@@ -332,36 +332,26 @@
}
//------------------Start of Serializable Implementation---------------------//
- private final static Map<TypeElement, NewSerializedForm> serializedForms = new HashMap<>();
+ private final Map<TypeElement, NewSerializedForm> serializedForms = new HashMap<>();
- public SortedSet<VariableElement> getSerializableFields(Utils utils, TypeElement klass) {
- NewSerializedForm sf = serializedForms.get(klass);
- if (sf == null) {
- sf = new NewSerializedForm(utils, configuration.docEnv.getElementUtils(), klass);
- serializedForms.put(klass, sf);
- }
- return sf.fields;
+ private NewSerializedForm getSerializedForm(TypeElement typeElem) {
+ return serializedForms.computeIfAbsent(typeElem,
+ te -> new NewSerializedForm(utils, configuration.docEnv.getElementUtils(), te));
}
- public SortedSet<ExecutableElement> getSerializationMethods(Utils utils, TypeElement klass) {
- NewSerializedForm sf = serializedForms.get(klass);
- if (sf == null) {
- sf = new NewSerializedForm(utils, configuration.docEnv.getElementUtils(), klass);
- serializedForms.put(klass, sf);
- }
- return sf.methods;
+ public SortedSet<VariableElement> getSerializableFields(TypeElement typeElem) {
+ return getSerializedForm(typeElem).fields;
}
- public boolean definesSerializableFields(Utils utils, TypeElement klass) {
- if (!utils.isSerializable(klass) || utils.isExternalizable(klass)) {
+ public SortedSet<ExecutableElement> getSerializationMethods(TypeElement typeElem) {
+ return getSerializedForm(typeElem).methods;
+ }
+
+ public boolean definesSerializableFields(TypeElement typeElem) {
+ if (!utils.isSerializable(typeElem) || utils.isExternalizable(typeElem)) {
return false;
} else {
- NewSerializedForm sf = serializedForms.get(klass);
- if (sf == null) {
- sf = new NewSerializedForm(utils, configuration.docEnv.getElementUtils(), klass);
- serializedForms.put(klass, sf);
- }
- return sf.definesSerializableFields;
+ return getSerializedForm(typeElem).definesSerializableFields;
}
}
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java Mon Oct 21 11:35:36 2019 -0700
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java Mon Oct 21 13:25:36 2019 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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
@@ -417,15 +417,15 @@
}
public SortedSet<VariableElement> serializableFields(TypeElement aclass) {
- return configuration.workArounds.getSerializableFields(this, aclass);
+ return configuration.workArounds.getSerializableFields(aclass);
}
public SortedSet<ExecutableElement> serializationMethods(TypeElement aclass) {
- return configuration.workArounds.getSerializationMethods(this, aclass);
+ return configuration.workArounds.getSerializationMethods(aclass);
}
public boolean definesSerializableFields(TypeElement aclass) {
- return configuration.workArounds.definesSerializableFields(this, aclass);
+ return configuration.workArounds.definesSerializableFields( aclass);
}
public String modifiersToString(Element e, boolean trailingSpace) {