Scheme/Value validation

Description

Hi there,

I recently downloaded the modules-0.3.2.jar, wrote a test case using an
example media RSS 2.0 from http://search.yahoo.com/mrss, and got the
following exception:

Apr 13, 2009 12:30:22 PM
com.sun.syndication.feed.module.mediarss.io.MediaModuleParser parseMetadata
WARNING: Exception parsing rating tag.
java.lang.NullPointerException: Scheme and value cannot be null.
at
com.sun.syndication.feed.module.mediarss.types.AbstractSchemeValue.<init>(AbstractSchemeValue.java:40)
at
com.sun.syndication.feed.module.mediarss.types.Rating.<init>(Rating.java:66)
at
com.sun.syndication.feed.module.mediarss.io.MediaModuleParser.parseMetadata(MediaModuleParser.java:331)
at
com.sun.syndication.feed.module.mediarss.io.MediaModuleParser.parseGroup(MediaModuleParser.java:226)
at
com.sun.syndication.feed.module.mediarss.io.MediaModuleParser.parse(MediaModuleParser.java:97)
at
com.sun.syndication.io.impl.ModuleParsers.parseModules(ModuleParsers.java:51)
at
com.sun.syndication.io.impl.BaseWireFeedParser.parseItemModules(BaseWireFeedParser.java:68)
at
com.sun.syndication.io.impl.RSS090Parser.parseItem(RSS090Parser.java:290)
at
com.sun.syndication.io.impl.RSS091UserlandParser.parseItem(RSS091UserlandParser.java:228)
at
com.sun.syndication.io.impl.RSS092Parser.parseItem(RSS092Parser.java:81)
at
com.sun.syndication.io.impl.RSS093Parser.parseItem(RSS093Parser.java:39)
at
com.sun.syndication.io.impl.RSS094Parser.parseItem(RSS094Parser.java:68)
at
com.sun.syndication.io.impl.RSS090Parser.parseItems(RSS090Parser.java:263)
at
com.sun.syndication.io.impl.RSS090Parser.parseChannel(RSS090Parser.java:178)
at
com.sun.syndication.io.impl.RSS091UserlandParser.parseChannel(RSS091UserlandParser.java:84)
at
com.sun.syndication.io.impl.RSS092Parser.parseChannel(RSS092Parser.java:49)
at
com.sun.syndication.io.impl.RSS094Parser.parseChannel(RSS094Parser.java:45)
at
com.sun.syndication.io.impl.RSS090Parser.parse(RSS090Parser.java:82)
at
com.sun.syndication.io.WireFeedInput.build(WireFeedInput.java:277)
at
com.sun.syndication.io.WireFeedInput.build(WireFeedInput.java:195)
at
com.sun.syndication.io.SyndFeedInput.build(SyndFeedInput.java:123)

I downloaded the sources, took a look at the line in question, and noticed
the following condition:

if ((scheme == null) || (value == null)) {
throw new NullPointerException("Scheme and value cannot be
null.");
}

Shouldn't the OR operator actually be an AND operator? The exception (even
though it's just logged as a warning message) occurs when it tries to handle
the following tag:

<media:rating>nonadult</media:rating>

The optional 'scheme' attribute for the media:rating tag turns out to be
null causing the condition above to evaluate to true and the exception to be
thrown. From reading the media RSS spec, it says that "If this attribute is
not included, the default scheme is urn:simple (adult | nonadult)". So
either this value is not getting set to "urn:simple" somewhere upstream in
the call stack or the conditional operator should be changed to AND. Another
thing I noticed is that the parser getting used is RSS090Parser and not the
RSS20YahooParser which might also be causing the problem. Haven't figured
that out yet, but here's the example which I used:

<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
<channel>
<title>Song Site</title>
<link>http://www.foo.com</link>
<description>Songs galore at different bitrates</description>
<item>
<title>Cool song by an artist</title>
<link>http://www.foo.com/item1.htm</link>
<media:group>
<media:content url="http://www.foo.com/song64kbps.mp3"
fileSize="1000" bitrate="64" type="audio/mpeg"
isDefault="true" expression="full"/>
<media:content url="http://www.foo.com/song128kbps.mp3"
fileSize="2000" bitrate="128" type="audio/mpeg"
expression="full"/>
<media:content url="http://www.foo.com/song256kbps.mp3"
fileSize="4000" bitrate="256" type="audio/mpeg"
expression="full"/>
<media:content url="http://www.foo.com/song512kbps.mp3.torrent"
fileSize="8000" type="application/x-bittorrent;enclosed=audio/mpeg"
expression="full"/>
<media:content url="http://www.foo.com/song.wav"
fileSize="16000" type="audio/x-wav" expression="full"/>
<media:credit role="musician">band member 1</media:credit>
<media:credit role="musician">band member 2</media:credit>
<media:category>music/artist name/album/song</media:category>
<media:rating>nonadult</media:rating>
</media:group>
</item>
</channel>
</rss>

Anybody provide any insights into this? I can simply patch it by changing
the conditional operator, but if someone knows of the "proper" solution,
then I'd like to hear it.

Environment

None

Status

Assignee

Robert Cooper

Reporter

Robert Cooper

Labels

None

Participants

None

Priority

Major
Configure