Some context and code in which this fails and data with which this fails would
help.
Also the version you are using would help.
However, inspecting 2.0.6 code (which is the most handy on the machine I'm on
-- I suspect other code is similar),
there is only one place in __setLastMatchResult() where you can get a NPE.
__lastMatchResult is non-null. OpCode is non-null. However, __originalInput
MIGHT be null. Hence you can get a NPE where the __originalInput.length is
tested. Check your code whether the string in contains() is null, and always
check if the result is true.
E.g.,
private PatternCompiler m_compiler = new Perl5Compiler();
private PatternMatcher m_matcher = new Perl5Matcher();
private Pattern m_commentRegex = m_compiler.compile ( "#" );
/** Extract comment from string. */
public String findComment ( String s )
{
if ( s == null ) return null;
if ( m_matcher.contains ( s, m_commentRegex ) )
{
MatchResult result = m_matcher.getMatch();
String comment = s.substring ( result.endOffset(0) );
return comment;
}
return null;
}
Enjoy.
Kevin Markey
-----Original Message-----
From: Balaji [mailto:[email protected]]
Sent: Tue 3/31/2009 6:22 AM
To: [email protected]
Subject: Is this a bug with oro?
Hello,
I occassionally get the below exception. The call to getMatch is causing a
NullPointerException.
Caused by: java.lang.NullPointerException
at org.apache.oro.text.regex.Perl5Matcher.__setLastMatchResult(Unknown
Source)
at org.apache.oro.text.regex.Perl5Matcher.getMatch(Unknown Source)
Here is what the API documentation says,
A MatchResult instance containing the pattern match found by the last call
to any one of the matches() or contains() methods. If no match was found by
the last call, returns null.
I believe this is a bug. Can you guys, please confirm?
If so, is there a fix or a workaround for this bug?
Any help will be greatly appreciated.
Thanks,
Balaji Prabhakaran