# HG changeset patch # User jjg # Date 1571689536 25200 # Node ID fa1f838b54865008e2046b1d93ea9f123882aa57 # Parent 449555c346d928a9086bd5ec2ceb1a597a0164a9 8231587: Memory leak in WorkArounds.serializedForms Reviewed-by: hannesw Contributed-by: fw@deneb.enyo.de diff -r 449555c346d9 -r fa1f838b5486 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/WorkArounds.java --- 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 serializedForms = new HashMap<>(); + private final Map serializedForms = new HashMap<>(); - public SortedSet 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 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 getSerializableFields(TypeElement typeElem) { + return getSerializedForm(typeElem).fields; } - public boolean definesSerializableFields(Utils utils, TypeElement klass) { - if (!utils.isSerializable(klass) || utils.isExternalizable(klass)) { + public SortedSet 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; } } diff -r 449555c346d9 -r fa1f838b5486 src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java --- 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 serializableFields(TypeElement aclass) { - return configuration.workArounds.getSerializableFields(this, aclass); + return configuration.workArounds.getSerializableFields(aclass); } public SortedSet 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) {