8148417: Memory leak in javadoc DocFileFactory
authorjjg
Wed, 27 Jan 2016 20:47:21 -0800
changeset 35420 9303ae941f69
parent 35419 6adb831721fe
child 35421 145c5b260ea1
8148417: Memory leak in javadoc DocFileFactory Reviewed-by: ksrini
langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java
langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/internal/toolkit/util/DocFileFactory.java
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java	Wed Jan 27 14:44:33 2016 -0800
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java	Wed Jan 27 20:47:21 2016 -0800
@@ -311,6 +311,8 @@
     public final Map<ProgramElementDoc, ProgramElementDoc> classPropertiesMap = new HashMap<>();
     public final Map<ProgramElementDoc, GetterSetter> getterSetterMap = new HashMap<>();
 
+    public DocFileFactory docFileFactory;
+
     /**
      * Constructor. Constructs the message retriever with resource file.
      */
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/internal/toolkit/util/DocFileFactory.java	Wed Jan 27 14:44:33 2016 -0800
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/doclets/internal/toolkit/util/DocFileFactory.java	Wed Jan 27 20:47:21 2016 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2016, 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
@@ -25,9 +25,6 @@
 
 package com.sun.tools.doclets.internal.toolkit.util;
 
-import java.util.Map;
-import java.util.WeakHashMap;
-
 import javax.tools.JavaFileManager;
 import javax.tools.JavaFileManager.Location;
 import javax.tools.StandardJavaFileManager;
@@ -45,15 +42,13 @@
  *
  * @since 1.8
  */
-abstract class DocFileFactory {
-    private static final Map<Configuration, DocFileFactory> factories = new WeakHashMap<>();
-
+public abstract class DocFileFactory {
     /**
      * Get the appropriate factory, based on the file manager given in the
      * configuration.
      */
     static synchronized DocFileFactory getFactory(Configuration configuration) {
-        DocFileFactory f = factories.get(configuration);
+        DocFileFactory f = configuration.docFileFactory;
         if (f == null) {
             JavaFileManager fm = configuration.getFileManager();
             if (fm instanceof StandardJavaFileManager) {
@@ -61,7 +56,7 @@
             } else {
                 throw new IllegalStateException();
             }
-            factories.put(configuration, f);
+            configuration.docFileFactory = f;
         }
         return f;
     }