You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Gary Gregory <ga...@gmail.com> on 2016/06/12 20:05:12 UTC
Re: svn commit: r1748015 - in /commons/proper/imaging/trunk/src:
changes/changes.xml main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java
test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java
This looks like a candidate for the more efficient switch on string.
Gary
On Sun, Jun 12, 2016 at 7:47 AM, <br...@apache.org> wrote:
> Author: britter
> Date: Sun Jun 12 14:47:11 2016
> New Revision: 1748015
>
> URL: http://svn.apache.org/viewvc?rev=1748015&view=rev
> Log:
> IMAGING-178: PnmImageParser does not check the validity of input PAM
> header. Thanks to emopers. This also fixes #20 from github.
>
> Modified:
> commons/proper/imaging/trunk/src/changes/changes.xml
>
> commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java
>
> commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java
>
> Modified: commons/proper/imaging/trunk/src/changes/changes.xml
> URL:
> http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/changes/changes.xml?rev=1748015&r1=1748014&r2=1748015&view=diff
>
> ==============================================================================
> --- commons/proper/imaging/trunk/src/changes/changes.xml (original)
> +++ commons/proper/imaging/trunk/src/changes/changes.xml Sun Jun 12
> 14:47:11 2016
> @@ -46,6 +46,9 @@ The <action> type attribute can be add,u
> <body>
>
> <release version="1.0" date="TBA" description="First major release">
> + <action issue="IMAGING-178" dev="britter" type="fix"
> due-to="emopers">
> + PnmImageParser does not check the validity of input PAM header.
> + </action>
> <action issue="IMAGING-184" dev="ggregory" type="update">
> Update platform from Java 5 to 7
> </action>
>
> Modified:
> commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java
> URL:
> http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java?rev=1748015&r1=1748014&r2=1748015&view=diff
>
> ==============================================================================
> ---
> commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java
> (original)
> +++
> commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java
> Sun Jun 12 14:47:11 2016
> @@ -157,18 +157,28 @@ public class PnmImageParser extends Imag
> final String type = tokenizer.nextToken();
> if ("WIDTH".equals(type)) {
> seenWidth = true;
> + if(!tokenizer.hasMoreTokens())
> + throw new ImageReadException("PAM header has no
> WIDTH value");
> width = Integer.parseInt(tokenizer.nextToken());
> } else if ("HEIGHT".equals(type)) {
> seenHeight = true;
> + if(!tokenizer.hasMoreTokens())
> + throw new ImageReadException("PAM header has no
> HEIGHT value");
> height = Integer.parseInt(tokenizer.nextToken());
> } else if ("DEPTH".equals(type)) {
> seenDepth = true;
> + if(!tokenizer.hasMoreTokens())
> + throw new ImageReadException("PAM header has no
> DEPTH value");
> depth = Integer.parseInt(tokenizer.nextToken());
> } else if ("MAXVAL".equals(type)) {
> seenMaxVal = true;
> + if(!tokenizer.hasMoreTokens())
> + throw new ImageReadException("PAM header has no
> MAXVAL value");
> maxVal = Integer.parseInt(tokenizer.nextToken());
> } else if ("TUPLTYPE".equals(type)) {
> seenTupleType = true;
> + if(!tokenizer.hasMoreTokens())
> + throw new ImageReadException("PAM header has no
> TUPLTYPE value");
> tupleType.append(tokenizer.nextToken());
> } else if ("ENDHDR".equals(type)) {
> break;
>
> Modified:
> commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java
> URL:
> http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java?rev=1748015&r1=1748014&r2=1748015&view=diff
>
> ==============================================================================
> ---
> commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java
> (original)
> +++
> commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java
> Sun Jun 12 14:47:11 2016
> @@ -46,4 +46,12 @@ public class PnmImageParserTest {
> PnmImageParser underTest = new PnmImageParser();
> underTest.getImageInfo(bytes, params);
> }
> +
> + @Test(expected = ImageReadException.class)
> + public void testGetImageInfo_missingWidthValue() throws
> ImageReadException, IOException {
> + byte[] bytes = "P7\nWIDTH \n".getBytes(US_ASCII);
> + Map<String, Object> params = Collections.emptyMap();
> + PnmImageParser underTest = new PnmImageParser();
> + underTest.getImageInfo(bytes, params);
> + }
> }
>
>
>
--
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Re: svn commit: r1748015 - in /commons/proper/imaging/trunk/src:
changes/changes.xml main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java
test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java
Posted by Gary Gregory <ga...@gmail.com>.
On Sun, Jun 12, 2016 at 2:12 PM, James Carman <ja...@carmanconsulting.com>
wrote:
> Doesn't it all compiled down to the same thing?
You're assuming all compilers from all vendors would be smart enough to
optimize a cascading if-else into a switch-on-string. I would not bet my
money on that. But I do know how a switch-on-string works, it's a look up
table, O(1), and also less-error prone IMO.
Gary
> It gets optimized at
> runtime anyway. I would go for the more readable option, unless there are
> extremely compelling performance numbers.
>
> On Sun, Jun 12, 2016 at 4:38 PM Benedikt Ritter <br...@apache.org>
> wrote:
>
> > Yes, the if-else could also be implemented using a switch statement. But
> is
> > that really more efficient?
> >
> > Benedikt
> >
> > Gary Gregory <ga...@gmail.com> schrieb am So., 12. Juni 2016 um
> > 22:05:
> >
> > > This looks like a candidate for the more efficient switch on string.
> > >
> > > Gary
> > >
> > > On Sun, Jun 12, 2016 at 7:47 AM, <br...@apache.org> wrote:
> > >
> > > > Author: britter
> > > > Date: Sun Jun 12 14:47:11 2016
> > > > New Revision: 1748015
> > > >
> > > > URL: http://svn.apache.org/viewvc?rev=1748015&view=rev
> > > > Log:
> > > > IMAGING-178: PnmImageParser does not check the validity of input PAM
> > > > header. Thanks to emopers. This also fixes #20 from github.
> > > >
> > > > Modified:
> > > > commons/proper/imaging/trunk/src/changes/changes.xml
> > > >
> > > >
> > >
> >
> commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java
> > > >
> > > >
> > >
> >
> commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java
> > > >
> > > > Modified: commons/proper/imaging/trunk/src/changes/changes.xml
> > > > URL:
> > > >
> > >
> >
> http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/changes/changes.xml?rev=1748015&r1=1748014&r2=1748015&view=diff
> > > >
> > > >
> > >
> >
> ==============================================================================
> > > > --- commons/proper/imaging/trunk/src/changes/changes.xml (original)
> > > > +++ commons/proper/imaging/trunk/src/changes/changes.xml Sun Jun 12
> > > > 14:47:11 2016
> > > > @@ -46,6 +46,9 @@ The <action> type attribute can be add,u
> > > > <body>
> > > >
> > > > <release version="1.0" date="TBA" description="First major
> > release">
> > > > + <action issue="IMAGING-178" dev="britter" type="fix"
> > > > due-to="emopers">
> > > > + PnmImageParser does not check the validity of input PAM
> > header.
> > > > + </action>
> > > > <action issue="IMAGING-184" dev="ggregory" type="update">
> > > > Update platform from Java 5 to 7
> > > > </action>
> > > >
> > > > Modified:
> > > >
> > >
> >
> commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java
> > > > URL:
> > > >
> > >
> >
> http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java?rev=1748015&r1=1748014&r2=1748015&view=diff
> > > >
> > > >
> > >
> >
> ==============================================================================
> > > > ---
> > > >
> > >
> >
> commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java
> > > > (original)
> > > > +++
> > > >
> > >
> >
> commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java
> > > > Sun Jun 12 14:47:11 2016
> > > > @@ -157,18 +157,28 @@ public class PnmImageParser extends Imag
> > > > final String type = tokenizer.nextToken();
> > > > if ("WIDTH".equals(type)) {
> > > > seenWidth = true;
> > > > + if(!tokenizer.hasMoreTokens())
> > > > + throw new ImageReadException("PAM header has
> > no
> > > > WIDTH value");
> > > > width = Integer.parseInt(tokenizer.nextToken());
> > > > } else if ("HEIGHT".equals(type)) {
> > > > seenHeight = true;
> > > > + if(!tokenizer.hasMoreTokens())
> > > > + throw new ImageReadException("PAM header has
> > no
> > > > HEIGHT value");
> > > > height =
> Integer.parseInt(tokenizer.nextToken());
> > > > } else if ("DEPTH".equals(type)) {
> > > > seenDepth = true;
> > > > + if(!tokenizer.hasMoreTokens())
> > > > + throw new ImageReadException("PAM header has
> > no
> > > > DEPTH value");
> > > > depth = Integer.parseInt(tokenizer.nextToken());
> > > > } else if ("MAXVAL".equals(type)) {
> > > > seenMaxVal = true;
> > > > + if(!tokenizer.hasMoreTokens())
> > > > + throw new ImageReadException("PAM header has
> > no
> > > > MAXVAL value");
> > > > maxVal =
> Integer.parseInt(tokenizer.nextToken());
> > > > } else if ("TUPLTYPE".equals(type)) {
> > > > seenTupleType = true;
> > > > + if(!tokenizer.hasMoreTokens())
> > > > + throw new ImageReadException("PAM header has
> > no
> > > > TUPLTYPE value");
> > > > tupleType.append(tokenizer.nextToken());
> > > > } else if ("ENDHDR".equals(type)) {
> > > > break;
> > > >
> > > > Modified:
> > > >
> > >
> >
> commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java
> > > > URL:
> > > >
> > >
> >
> http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java?rev=1748015&r1=1748014&r2=1748015&view=diff
> > > >
> > > >
> > >
> >
> ==============================================================================
> > > > ---
> > > >
> > >
> >
> commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java
> > > > (original)
> > > > +++
> > > >
> > >
> >
> commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java
> > > > Sun Jun 12 14:47:11 2016
> > > > @@ -46,4 +46,12 @@ public class PnmImageParserTest {
> > > > PnmImageParser underTest = new PnmImageParser();
> > > > underTest.getImageInfo(bytes, params);
> > > > }
> > > > +
> > > > + @Test(expected = ImageReadException.class)
> > > > + public void testGetImageInfo_missingWidthValue() throws
> > > > ImageReadException, IOException {
> > > > + byte[] bytes = "P7\nWIDTH \n".getBytes(US_ASCII);
> > > > + Map<String, Object> params = Collections.emptyMap();
> > > > + PnmImageParser underTest = new PnmImageParser();
> > > > + underTest.getImageInfo(bytes, params);
> > > > + }
> > > > }
> > > >
> > > >
> > > >
> > >
> > >
> > > --
> > > E-Mail: garydgregory@gmail.com | ggregory@apache.org
> > > Java Persistence with Hibernate, Second Edition
> > > <http://www.manning.com/bauer3/>
> > > JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> > > Spring Batch in Action <http://www.manning.com/templier/>
> > > Blog: http://garygregory.wordpress.com
> > > Home: http://garygregory.com/
> > > Tweet! http://twitter.com/GaryGregory
> > >
> >
>
--
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Re: svn commit: r1748015 - in /commons/proper/imaging/trunk/src:
changes/changes.xml main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java
test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java
Posted by James Carman <ja...@carmanconsulting.com>.
Doesn't it all compiled down to the same thing? It gets optimized at
runtime anyway. I would go for the more readable option, unless there are
extremely compelling performance numbers.
On Sun, Jun 12, 2016 at 4:38 PM Benedikt Ritter <br...@apache.org> wrote:
> Yes, the if-else could also be implemented using a switch statement. But is
> that really more efficient?
>
> Benedikt
>
> Gary Gregory <ga...@gmail.com> schrieb am So., 12. Juni 2016 um
> 22:05:
>
> > This looks like a candidate for the more efficient switch on string.
> >
> > Gary
> >
> > On Sun, Jun 12, 2016 at 7:47 AM, <br...@apache.org> wrote:
> >
> > > Author: britter
> > > Date: Sun Jun 12 14:47:11 2016
> > > New Revision: 1748015
> > >
> > > URL: http://svn.apache.org/viewvc?rev=1748015&view=rev
> > > Log:
> > > IMAGING-178: PnmImageParser does not check the validity of input PAM
> > > header. Thanks to emopers. This also fixes #20 from github.
> > >
> > > Modified:
> > > commons/proper/imaging/trunk/src/changes/changes.xml
> > >
> > >
> >
> commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java
> > >
> > >
> >
> commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java
> > >
> > > Modified: commons/proper/imaging/trunk/src/changes/changes.xml
> > > URL:
> > >
> >
> http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/changes/changes.xml?rev=1748015&r1=1748014&r2=1748015&view=diff
> > >
> > >
> >
> ==============================================================================
> > > --- commons/proper/imaging/trunk/src/changes/changes.xml (original)
> > > +++ commons/proper/imaging/trunk/src/changes/changes.xml Sun Jun 12
> > > 14:47:11 2016
> > > @@ -46,6 +46,9 @@ The <action> type attribute can be add,u
> > > <body>
> > >
> > > <release version="1.0" date="TBA" description="First major
> release">
> > > + <action issue="IMAGING-178" dev="britter" type="fix"
> > > due-to="emopers">
> > > + PnmImageParser does not check the validity of input PAM
> header.
> > > + </action>
> > > <action issue="IMAGING-184" dev="ggregory" type="update">
> > > Update platform from Java 5 to 7
> > > </action>
> > >
> > > Modified:
> > >
> >
> commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java
> > > URL:
> > >
> >
> http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java?rev=1748015&r1=1748014&r2=1748015&view=diff
> > >
> > >
> >
> ==============================================================================
> > > ---
> > >
> >
> commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java
> > > (original)
> > > +++
> > >
> >
> commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java
> > > Sun Jun 12 14:47:11 2016
> > > @@ -157,18 +157,28 @@ public class PnmImageParser extends Imag
> > > final String type = tokenizer.nextToken();
> > > if ("WIDTH".equals(type)) {
> > > seenWidth = true;
> > > + if(!tokenizer.hasMoreTokens())
> > > + throw new ImageReadException("PAM header has
> no
> > > WIDTH value");
> > > width = Integer.parseInt(tokenizer.nextToken());
> > > } else if ("HEIGHT".equals(type)) {
> > > seenHeight = true;
> > > + if(!tokenizer.hasMoreTokens())
> > > + throw new ImageReadException("PAM header has
> no
> > > HEIGHT value");
> > > height = Integer.parseInt(tokenizer.nextToken());
> > > } else if ("DEPTH".equals(type)) {
> > > seenDepth = true;
> > > + if(!tokenizer.hasMoreTokens())
> > > + throw new ImageReadException("PAM header has
> no
> > > DEPTH value");
> > > depth = Integer.parseInt(tokenizer.nextToken());
> > > } else if ("MAXVAL".equals(type)) {
> > > seenMaxVal = true;
> > > + if(!tokenizer.hasMoreTokens())
> > > + throw new ImageReadException("PAM header has
> no
> > > MAXVAL value");
> > > maxVal = Integer.parseInt(tokenizer.nextToken());
> > > } else if ("TUPLTYPE".equals(type)) {
> > > seenTupleType = true;
> > > + if(!tokenizer.hasMoreTokens())
> > > + throw new ImageReadException("PAM header has
> no
> > > TUPLTYPE value");
> > > tupleType.append(tokenizer.nextToken());
> > > } else if ("ENDHDR".equals(type)) {
> > > break;
> > >
> > > Modified:
> > >
> >
> commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java
> > > URL:
> > >
> >
> http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java?rev=1748015&r1=1748014&r2=1748015&view=diff
> > >
> > >
> >
> ==============================================================================
> > > ---
> > >
> >
> commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java
> > > (original)
> > > +++
> > >
> >
> commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java
> > > Sun Jun 12 14:47:11 2016
> > > @@ -46,4 +46,12 @@ public class PnmImageParserTest {
> > > PnmImageParser underTest = new PnmImageParser();
> > > underTest.getImageInfo(bytes, params);
> > > }
> > > +
> > > + @Test(expected = ImageReadException.class)
> > > + public void testGetImageInfo_missingWidthValue() throws
> > > ImageReadException, IOException {
> > > + byte[] bytes = "P7\nWIDTH \n".getBytes(US_ASCII);
> > > + Map<String, Object> params = Collections.emptyMap();
> > > + PnmImageParser underTest = new PnmImageParser();
> > > + underTest.getImageInfo(bytes, params);
> > > + }
> > > }
> > >
> > >
> > >
> >
> >
> > --
> > E-Mail: garydgregory@gmail.com | ggregory@apache.org
> > Java Persistence with Hibernate, Second Edition
> > <http://www.manning.com/bauer3/>
> > JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> > Spring Batch in Action <http://www.manning.com/templier/>
> > Blog: http://garygregory.wordpress.com
> > Home: http://garygregory.com/
> > Tweet! http://twitter.com/GaryGregory
> >
>
Re: svn commit: r1748015 - in /commons/proper/imaging/trunk/src:
changes/changes.xml main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java
test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java
Posted by Benedikt Ritter <br...@apache.org>.
Yes, the if-else could also be implemented using a switch statement. But is
that really more efficient?
Benedikt
Gary Gregory <ga...@gmail.com> schrieb am So., 12. Juni 2016 um
22:05:
> This looks like a candidate for the more efficient switch on string.
>
> Gary
>
> On Sun, Jun 12, 2016 at 7:47 AM, <br...@apache.org> wrote:
>
> > Author: britter
> > Date: Sun Jun 12 14:47:11 2016
> > New Revision: 1748015
> >
> > URL: http://svn.apache.org/viewvc?rev=1748015&view=rev
> > Log:
> > IMAGING-178: PnmImageParser does not check the validity of input PAM
> > header. Thanks to emopers. This also fixes #20 from github.
> >
> > Modified:
> > commons/proper/imaging/trunk/src/changes/changes.xml
> >
> >
> commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java
> >
> >
> commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java
> >
> > Modified: commons/proper/imaging/trunk/src/changes/changes.xml
> > URL:
> >
> http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/changes/changes.xml?rev=1748015&r1=1748014&r2=1748015&view=diff
> >
> >
> ==============================================================================
> > --- commons/proper/imaging/trunk/src/changes/changes.xml (original)
> > +++ commons/proper/imaging/trunk/src/changes/changes.xml Sun Jun 12
> > 14:47:11 2016
> > @@ -46,6 +46,9 @@ The <action> type attribute can be add,u
> > <body>
> >
> > <release version="1.0" date="TBA" description="First major release">
> > + <action issue="IMAGING-178" dev="britter" type="fix"
> > due-to="emopers">
> > + PnmImageParser does not check the validity of input PAM header.
> > + </action>
> > <action issue="IMAGING-184" dev="ggregory" type="update">
> > Update platform from Java 5 to 7
> > </action>
> >
> > Modified:
> >
> commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java
> > URL:
> >
> http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java?rev=1748015&r1=1748014&r2=1748015&view=diff
> >
> >
> ==============================================================================
> > ---
> >
> commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java
> > (original)
> > +++
> >
> commons/proper/imaging/trunk/src/main/java/org/apache/commons/imaging/formats/pnm/PnmImageParser.java
> > Sun Jun 12 14:47:11 2016
> > @@ -157,18 +157,28 @@ public class PnmImageParser extends Imag
> > final String type = tokenizer.nextToken();
> > if ("WIDTH".equals(type)) {
> > seenWidth = true;
> > + if(!tokenizer.hasMoreTokens())
> > + throw new ImageReadException("PAM header has no
> > WIDTH value");
> > width = Integer.parseInt(tokenizer.nextToken());
> > } else if ("HEIGHT".equals(type)) {
> > seenHeight = true;
> > + if(!tokenizer.hasMoreTokens())
> > + throw new ImageReadException("PAM header has no
> > HEIGHT value");
> > height = Integer.parseInt(tokenizer.nextToken());
> > } else if ("DEPTH".equals(type)) {
> > seenDepth = true;
> > + if(!tokenizer.hasMoreTokens())
> > + throw new ImageReadException("PAM header has no
> > DEPTH value");
> > depth = Integer.parseInt(tokenizer.nextToken());
> > } else if ("MAXVAL".equals(type)) {
> > seenMaxVal = true;
> > + if(!tokenizer.hasMoreTokens())
> > + throw new ImageReadException("PAM header has no
> > MAXVAL value");
> > maxVal = Integer.parseInt(tokenizer.nextToken());
> > } else if ("TUPLTYPE".equals(type)) {
> > seenTupleType = true;
> > + if(!tokenizer.hasMoreTokens())
> > + throw new ImageReadException("PAM header has no
> > TUPLTYPE value");
> > tupleType.append(tokenizer.nextToken());
> > } else if ("ENDHDR".equals(type)) {
> > break;
> >
> > Modified:
> >
> commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java
> > URL:
> >
> http://svn.apache.org/viewvc/commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java?rev=1748015&r1=1748014&r2=1748015&view=diff
> >
> >
> ==============================================================================
> > ---
> >
> commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java
> > (original)
> > +++
> >
> commons/proper/imaging/trunk/src/test/java/org/apache/commons/imaging/formats/pnm/PnmImageParserTest.java
> > Sun Jun 12 14:47:11 2016
> > @@ -46,4 +46,12 @@ public class PnmImageParserTest {
> > PnmImageParser underTest = new PnmImageParser();
> > underTest.getImageInfo(bytes, params);
> > }
> > +
> > + @Test(expected = ImageReadException.class)
> > + public void testGetImageInfo_missingWidthValue() throws
> > ImageReadException, IOException {
> > + byte[] bytes = "P7\nWIDTH \n".getBytes(US_ASCII);
> > + Map<String, Object> params = Collections.emptyMap();
> > + PnmImageParser underTest = new PnmImageParser();
> > + underTest.getImageInfo(bytes, params);
> > + }
> > }
> >
> >
> >
>
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition
> <http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>