changeset 35420:9303ae941f69

8148417: Memory leak in javadoc DocFileFactory Reviewed-by: ksrini
author jjg
date Wed, 27 Jan 2016 20:47:21 -0800
parents 6adb831721fe
children 145c5b260ea1
files 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
diffstat 2 files changed, 6 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- 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;
     }