/patches/openjdk/8002070-remove_logger_stack_search.patch

https://bitbucket.org/Ringdingcoder/icedtea6 · Patch · 152 lines · 140 code · 12 blank · 0 comment · 0 complexity · 75021c68547a362083f6db2dede03264 MD5 · raw file

  1. changeset: 4948:4a67dd684bc2
  2. user: andrew
  3. date: Tue Jun 18 08:07:48 2013 -0500
  4. files: src/share/classes/java/util/logging/Logger.java
  5. description:
  6. 8002070: Remove the stack search for a resource bundle for Logger to use
  7. Summary: The fragile, vulnerable, stack crawling has been eliminated from findResourceBundle(String)
  8. Reviewed-by: mchung, alanb
  9. --- openjdk/jdk/src/share/classes/java/util/logging/Logger.java
  10. +++ openjdk/jdk/src/share/classes/java/util/logging/Logger.java
  11. @@ -26,8 +26,16 @@
  12. package java.util.logging;
  13. -import java.util.*;
  14. +import java.lang.ref.WeakReference;
  15. +import java.security.AccessController;
  16. +import java.security.PrivilegedAction;
  17. +import java.util.ArrayList;
  18. +import java.util.Iterator;
  19. +import java.util.Locale;
  20. +import java.util.MissingResourceException;
  21. +import java.util.ResourceBundle;
  22. +import java.util.concurrent.CopyOnWriteArrayList;
  23. -import java.security.*;
  24. -import java.lang.ref.WeakReference;
  25. +import sun.reflect.CallerSensitive;
  26. +import sun.reflect.Reflection;
  27. /**
  28. @@ -100,14 +105,8 @@
  29. * <p>
  30. * When mapping ResourceBundle names to ResourceBundles, the Logger
  31. * will first try to use the Thread's ContextClassLoader. If that
  32. - * is null it will try the SystemClassLoader instead. As a temporary
  33. - * transition feature in the initial implementation, if the Logger is
  34. - * unable to locate a ResourceBundle from the ContextClassLoader or
  35. - * SystemClassLoader the Logger will also search up the class stack
  36. - * and use successive calling ClassLoaders to try to locate a ResourceBundle.
  37. - * (This call stack search is to allow containers to transition to
  38. - * using ContextClassLoaders and is likely to be removed in future
  39. - * versions.)
  40. + * is null it will try the
  41. + * {@linkplain java.lang.ClassLoader#getSystemClassLoader() system ClassLoader} instead.
  42. * <p>
  43. * Formatting (including localization) is the responsibility of
  44. * the output Handler, which will typically call a Formatter.
  45. @@ -1323,12 +1322,16 @@
  46. return useParentHandlers;
  47. }
  48. - // Private utility method to map a resource bundle name to an
  49. - // actual resource bundle, using a simple one-entry cache.
  50. - // Returns null for a null name.
  51. - // May also return null if we can't find the resource bundle and
  52. - // there is no suitable previous cached value.
  53. -
  54. + /**
  55. + * Private utility method to map a resource bundle name to an
  56. + * actual resource bundle, using a simple one-entry cache.
  57. + * Returns null for a null name.
  58. + * May also return null if we can't find the resource bundle and
  59. + * there is no suitable previous cached value.
  60. + *
  61. + * @param name the ResourceBundle to locate
  62. + * @return ResourceBundle specified by name or null if not found
  63. + */
  64. static final String SYSTEM_LOGGER_RB_NAME = "sun.util.logging.resources.logging";
  65. private static ResourceBundle findSystemResourceBundle(final Locale locale) {
  66. @@ -1355,8 +1358,8 @@
  67. Locale currentLocale = Locale.getDefault();
  68. // Normally we should hit on our simple one entry cache.
  69. - if (catalog != null && currentLocale == catalogLocale
  70. - && name == catalogName) {
  71. + if (catalog != null && currentLocale.equals(catalogLocale)
  72. + && name.equals(catalogName)) {
  73. return catalog;
  74. }
  75. @@ -1367,8 +1370,8 @@
  76. return catalog;
  77. }
  78. - // Use the thread's context ClassLoader. If there isn't one,
  79. - // use the SystemClassloader.
  80. + // Use the thread's context ClassLoader. If there isn't one, use the
  81. + // {@linkplain java.lang.ClassLoader#getSystemClassLoader() system ClassLoader}.
  82. ClassLoader cl = Thread.currentThread().getContextClassLoader();
  83. if (cl == null) {
  84. cl = ClassLoader.getSystemClassLoader();
  85. @@ -1379,45 +1382,8 @@
  86. catalogLocale = currentLocale;
  87. return catalog;
  88. } catch (MissingResourceException ex) {
  89. - // Woops. We can't find the ResourceBundle in the default
  90. - // ClassLoader. Drop through.
  91. + return null;
  92. }
  93. -
  94. -
  95. - // Fall back to searching up the call stack and trying each
  96. - // calling ClassLoader.
  97. - for (int ix = 0; ; ix++) {
  98. - Class clz = sun.reflect.Reflection.getCallerClass(ix);
  99. - if (clz == null) {
  100. - break;
  101. - }
  102. - ClassLoader cl2 = clz.getClassLoader();
  103. - if (cl2 == null) {
  104. - cl2 = ClassLoader.getSystemClassLoader();
  105. - }
  106. - if (cl == cl2) {
  107. - // We've already checked this classloader.
  108. - continue;
  109. - }
  110. - cl = cl2;
  111. - try {
  112. - catalog = ResourceBundle.getBundle(name, currentLocale, cl);
  113. - catalogName = name;
  114. - catalogLocale = currentLocale;
  115. - return catalog;
  116. - } catch (MissingResourceException ex) {
  117. - // Ok, this one didn't work either.
  118. - // Drop through, and try the next one.
  119. - }
  120. - }
  121. -
  122. - if (name.equals(catalogName)) {
  123. - // Return the previous cached value for that name.
  124. - // This may be null.
  125. - return catalog;
  126. - }
  127. - // Sorry, we're out of luck.
  128. - return null;
  129. }
  130. // Private utility method to initialize our one entry
  131. @@ -1428,8 +1395,7 @@
  132. if (name == null) {
  133. return;
  134. }
  135. - ResourceBundle rb = findResourceBundle(name);
  136. - if (rb == null) {
  137. + if (findResourceBundle(name) == null) {
  138. // We've failed to find an expected ResourceBundle.
  139. throw new MissingResourceException("Can't find " + name + " bundle", name, "");
  140. }