Return-Path: Delivered-To: apmail-james-mime4j-dev-archive@minotaur.apache.org Received: (qmail 70652 invoked from network); 15 Nov 2009 20:08:12 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 15 Nov 2009 20:08:12 -0000 Received: (qmail 30153 invoked by uid 500); 15 Nov 2009 20:08:12 -0000 Delivered-To: apmail-james-mime4j-dev-archive@james.apache.org Received: (qmail 30120 invoked by uid 500); 15 Nov 2009 20:08:12 -0000 Mailing-List: contact mime4j-dev-help@james.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: mime4j-dev@james.apache.org Delivered-To: mailing list mime4j-dev@james.apache.org Received: (qmail 30110 invoked by uid 99); 15 Nov 2009 20:08:12 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 15 Nov 2009 20:08:12 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 15 Nov 2009 20:08:09 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 8EAAE234C045 for ; Sun, 15 Nov 2009 12:07:48 -0800 (PST) Message-ID: <290784428.1258315668569.JavaMail.jira@brutus> Date: Sun, 15 Nov 2009 20:07:48 +0000 (UTC) From: "Markus Wiederkehr (JIRA)" To: mime4j-dev@james.apache.org Subject: [jira] Commented: (MIME4J-139) DelegatingFieldParser NPE problem In-Reply-To: <1288585394.1257240719579.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/MIME4J-139?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12778166#action_12778166 ] Markus Wiederkehr commented on MIME4J-139: ------------------------------------------ @Stefano: thanks for the explanation. This is what seems to happen chronologically in Stefanos DefaultFieldParserTest: 1) static initializer of DelegatingFieldParser 2) static initializer of DefaultFieldParser 3) static initializer of AbstractField 4) constructor of DelegatingFieldParser (invoked by AbstractField) 4.1) variable defaultParser is null (probably because UnstructuredField has not been completely initialized) 5) static initializer of UnstructuredField 6) constructor of DelegatingFieldParser (invoked by DefaultFieldParserTest) 6.1) variable defaultParser is not null (refers to an UnstructuredField instance) 7) Unit tests invokes AbstractField.parse() 8) NPE because of defaultParser being null in 3.1 Now what's funny is if you change defaultParser to private static the variable defaultParser is still null in 4.1! But after initialization has completed the variable points to the right object and the test passes. > DelegatingFieldParser NPE problem > --------------------------------- > > Key: MIME4J-139 > URL: https://issues.apache.org/jira/browse/MIME4J-139 > Project: JAMES Mime4j > Issue Type: Bug > Affects Versions: 0.6 > Environment: jre 1.6.11 > Reporter: Andrzej Rusin > Priority: Minor > Original Estimate: 0.08h > Remaining Estimate: 0.08h > > We have custom ContentHandlers that extend AbstractContentHandler and add some custom Fields that extend AbstractField. > We were getting: > java.lang.NullPointerException > at org.apache.james.mime4j.field.DelegatingFieldParser.parse(DelegatingFieldParser.java:51) > at org.apache.james.mime4j.field.AbstractField.parse(AbstractField.java:171) > at org.apache.james.mime4j.field.AbstractField.parse(AbstractField.java:63) > at org.apache.james.mime4j.message.MessageBuilder.field(MessageBuilder.java:101) > at org.apache.james.mime4j.parser.MimeStreamParser.parse(MimeStreamParser.java:121) > at org.apache.james.mime4j.message.Message.(Message.java:141) > at org.apache.james.mime4j.message.Message.(Message.java:100) > always AFTER the MimeStreamParser got invoked with our content handlers (so, not on our parsing, but eg. later, on normal > new Message(InputStream). > Looked like we are currupting something inside MimeStreamParser. > Then I noticed that DelegatingFieldParser.defaultParser is defined as: > private FieldParser defaultParser = UnstructuredField.PARSER; > while other field parsers have: > static final FieldParser PARSER = new FieldParser() {...} > So I changed DelegatingFieldParser.defaultParser to static final and the NPEs do not occur anymore. > I do not undestand exactly why this happens, but that are the facts. > Is there any reason why DelegatingFieldParser.defaultParser can't be static final? -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.