Bug 52664 - An incomplete fix for the NPE bug in MAPIMessage.java
Summary: An incomplete fix for the NPE bug in MAPIMessage.java
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSMF (show other bugs)
Version: unspecified
Hardware: PC All
: P2 critical (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-14 10:08 UTC by lianggt08
Modified: 2012-02-15 11:47 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description lianggt08 2012-02-14 10:08:46 UTC
The fix revision 1171628 was aimed to remove an NPE bug on the  "nameIdChunks " in the method "set7BitEncoding" of the file "/poi/trunk/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java" , but it is incomplete. 
Since the "nameIdChunks " could be null during the run-time execution, its value should also be null-checked before being dereferenced in other methods. 

The buggy code locations the same fix needs to be applied at are as bellows: 
 
Line 454 of the method "has7BitEncodingStrings()".



public boolean has7BitEncodingStrings() {
      for(Chunk c : mainChunks.getAll()) {
         if(c instanceof StringChunk) {
            if( ((StringChunk)c).getType() == Types.ASCII_STRING ) {
               return true;
            }
         }
      }
[Line 454]      for(Chunk c : nameIdChunks.getAll()) {
         if(c instanceof StringChunk) {
            if( ((StringChunk)c).getType() == Types.ASCII_STRING ) {
               return true;
            }
         }
      }
      for(RecipientChunks rc : recipientChunks) {
         for(Chunk c : rc.getAll()) {
            if(c instanceof StringChunk) {
               if( ((StringChunk)c).getType() == Types.ASCII_STRING ) {
                  return true;
               }
            }
         }
      }
      return false;
   }
Comment 1 Nick Burch 2012-02-14 12:58:22 UTC
nameIdChunks seems to already be null checked:

      if (nameIdChunks!=null) {
         for(Chunk c : nameIdChunks.getAll()) {
            if(c instanceof StringChunk) {
                ((StringChunk)c).set7BitEncoding(charset);
            }
         }
      }

Is something else needed, or does this problem refer to an older version of POI?
Comment 2 lianggt08 2012-02-15 05:54:35 UTC
You have checked a wrong code location. Please check the line 454 of the method "has7BitEncodingStrings", not the method "set7BitEncoding". 


Line 454 of the method "has7BitEncodingStrings()".



public boolean has7BitEncodingStrings() {
      for(Chunk c : mainChunks.getAll()) {
         if(c instanceof StringChunk) {
            if( ((StringChunk)c).getType() == Types.ASCII_STRING ) {
               return true;
            }
         }
      }
[Line 454]      for(Chunk c : nameIdChunks.getAll()) {
         if(c instanceof StringChunk) {
            if( ((StringChunk)c).getType() == Types.ASCII_STRING ) {
               return true;
            }
         }
      }
      for(RecipientChunks rc : recipientChunks) {
         for(Chunk c : rc.getAll()) {
            if(c instanceof StringChunk) {
               if( ((StringChunk)c).getType() == Types.ASCII_STRING ) {
                  return true;
               }
            }
         }
      }
      return false;
   }
Comment 3 Nick Burch 2012-02-15 11:47:21 UTC
Thanks, fixed in r1244449.