[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jboss-cvs-commits
Subject:    [jboss-cvs] jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc JDBCUtil.java
From:       Alexey Loubyansky <loubyansky () users ! sourceforge ! net>
Date:       2004-06-29 7:19:15
Message-ID: E1BfCtf-0002qF-HW () sc8-pr-cvs1 ! sourceforge ! net
[Download RAW message or body]

  User: loubyansky
  Date: 04/06/29 00:19:15

  Modified:    src/main/org/jboss/ejb/plugins/cmp/jdbc Tag: Branch_3_2
                        JDBCUtil.java
  Log:
  fixed NPE reading CLOBs when Clob.getCharacterStream() returns null.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.11.2.14 +31 -24    jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCUtil.java
  
  Index: JDBCUtil.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/cmp/jdbc/JDBCUtil.java,v
  retrieving revision 1.11.2.13
  retrieving revision 1.11.2.14
  diff -u -r1.11.2.13 -r1.11.2.14
  --- JDBCUtil.java	5 Apr 2004 09:32:19 -0000	1.11.2.13
  +++ JDBCUtil.java	29 Jun 2004 07:19:12 -0000	1.11.2.14
  @@ -478,37 +478,44 @@
            else
            {
               final Reader reader = clob.getCharacterStream();
  -            int intLength = (int)clob.length();
  -
  -            char[] chars;
  -            try
  +            if(reader != null)
               {
  -               if(intLength <= clob.length())
  -               {
  -                  chars = new char[intLength];
  -                  reader.read(chars);
  -                  content = String.valueOf(chars);
  -               }
  -               else
  +               int intLength = (int)clob.length();
  +
  +               char[] chars;
  +               try
                  {
  -                  StringBuffer buf = new StringBuffer(intLength);
  -                  chars = new char[8192];
  -                  int i = reader.read(chars);
  -                  while(i > 0)
  +                  if(intLength <= 8192)
  +                  {
  +                     chars = new char[intLength];
  +                     reader.read(chars);
  +                     content = String.valueOf(chars);
  +                  }
  +                  else
                     {
  -                     buf.append(chars, 0, i);
  -                     i = reader.read(chars);
  +                     StringBuffer buf = new StringBuffer(intLength);
  +                     chars = new char[8192];
  +                     int i = reader.read(chars);
  +                     while(i > 0)
  +                     {
  +                        buf.append(chars, 0, i);
  +                        i = reader.read(chars);
  +                     }
  +                     content = buf.toString();
                     }
  -                  content = buf.toString();
  +               }
  +               catch(IOException e)
  +               {
  +                  throw new SQLException("Failed to read CLOB character stream: " + e.getMessage());
  +               }
  +               finally
  +               {
  +                  safeClose(reader);
                  }
               }
  -            catch(IOException e)
  -            {
  -               throw new SQLException("Failed to read CLOB character stream: " + e.getMessage());
  -            }
  -            finally
  +            else
               {
  -               safeClose(reader);
  +               content = null;
               }
            }
   
  
  
  


-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
jboss-cvs-commits mailing list
jboss-cvs-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-cvs-commits
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic