Avoid NPEs
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sun, 16 Jan 2011 15:41:15 +0000 (15:41 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sun, 16 Jan 2011 15:41:15 +0000 (15:41 +0000)
Remove FindBugs warning

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1059587 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/naming/factory/SendMailFactory.java
res/findbugs/filter-false-positives.xml

index 57e0d35..16aeb79 100644 (file)
@@ -111,10 +111,16 @@ public class SendMailFactory implements ObjectFactory
                     MimeMessage message = new MimeMessage(
                         Session.getInstance(props));
                     try {
-                        String from = (String)ref.get("mail.from").getContent();
-                        message.setFrom(new InternetAddress(from));
+                        RefAddr fromAddr = ref.get("mail.from");
+                        String from = null;
+                        if (fromAddr != null) {
+                            from = (String)ref.get("mail.from").getContent();
+                        }
+                        if (from != null) {
+                            message.setFrom(new InternetAddress(from));
+                        }
                         message.setSubject("");
-                    } catch (Exception e) {}
+                    } catch (Exception e) {/*Ignore*/}
                     MimePartDataSource mds = new MimePartDataSource(message);
                     return mds;
                 }
index ed13569..27d4368 100644 (file)
     <Bug code="NS"/>
   </Match>
   <Match>
+    <!-- Simpler to catch Exception than to create dummy implementations of the
+         necessary exception hierarchy -->
+    <Class name="org.apache.naming.factory.SendMailFactory$1" />
+    <Method name="run" />
+    <Bug code="DE" />
+  </Match>
+  <Match>
     <!-- Class name needs to start with a lower case letter in this case -->
     <Class name="org.apache.naming.java.javaURLContextFactory" />
     <Bug code="Nm" />