Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8060438

ThreadLocalBufferAllocator would return null if the soft reference is gc'ed

    Details

    • Type: Bug
    • Status: In Progress
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 7u55, 9
    • Fix Version/s: tbd
    • Component/s: xml
    • Labels:

      Description

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
       java.lang.NullPointerException at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.<init>(UTF8Reader.java:120)

      It looks like there is a bug in ThreadLocalBufferAllocator.getBufferAllocator() that returns null when reference is gc'ed while it should never return null.

      Related source code:

      http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/com/sun/xml/internal/stream/util/ThreadLocalBufferAllocator.java

      41public class More ...ThreadLocalBufferAllocator {
      42 private static ThreadLocal tlba = new ThreadLocal();
      43
      44 public static BufferAllocator More ...getBufferAllocator() {
      45 SoftReference bAllocatorRef = (SoftReference) tlba.get();
      46 if (bAllocatorRef == null || bAllocatorRef.get() == null) {
      47 bAllocatorRef = new SoftReference(new BufferAllocator());
      48 tlba.set(bAllocatorRef);
      49 }
      50
      51 return (BufferAllocator) bAllocatorRef.get();
      52 }
      53}

      http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/com/sun/org/apache/xerces/internal/impl/io/UTF8Reader.java

      116 public UTF8Reader(InputStream inputStream, int size,
      117 MessageFormatter messageFormatter, Locale locale) {
      118 fInputStream = inputStream;
      119 BufferAllocator ba = ThreadLocalBufferAllocator.getBufferAllocator();
      120 fBuffer = ba.getByteBuffer(size);
      121 if (fBuffer == null) {
      122 fBuffer = new byte[size];
      123 }
      124 fFormatter = messageFormatter;
      125 fLocale = locale;
      126 } // <init>(InputStream, int, MessageFormatter, Locale)



      REPRODUCIBILITY :
      This bug can be reproduced occasionally.

        Attachments

          Activity

            People

            • Assignee:
              fyuan Frank Yuan
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated: