Author: ivaynberg
Date: Mon Jan 29 17:56:00 2007
New Revision: 501286
URL: http://svn.apache.org/viewvc?view=rev&rev=501286
Log:
avoid npes on a runtime exception
Modified:
incubator/wicket/branches/wicket-1.2.x/wicket/src/main/java/wicket/markup/parser/XmlPullParser.java
Modified:
incubator/wicket/branches/wicket-1.2.x/wicket/src/main/java/wicket/markup/parser/XmlPullParser.java
URL:
http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.2.x/wicket/src/main/java/wicket/markup/parser/XmlPullParser.java?view=diff&rev=501286&r1=501285&r2=501286
==============================================================================
---
incubator/wicket/branches/wicket-1.2.x/wicket/src/main/java/wicket/markup/parser/XmlPullParser.java
(original)
+++
incubator/wicket/branches/wicket-1.2.x/wicket/src/main/java/wicket/markup/parser/XmlPullParser.java
Mon Jan 29 17:56:00 2007
@@ -165,7 +165,7 @@
// There is no next matching tag
return null;
}
-
+
// Determine line number
this.input.countLinesTo(openBracketIndex);
@@ -174,8 +174,8 @@
if (closeBracketIndex == -1)
{
- throw new ParseException("No matching close bracket at
position "
- + openBracketIndex,
this.input.getPosition());
+ throw new ParseException("No matching close bracket at
position " + openBracketIndex,
+ this.input.getPosition());
}
// Get the tagtext between open and close brackets
@@ -197,7 +197,7 @@
}
// Conditional comment? <!--[if ...]>..<![endif]-->
- if (tagText.startsWith("!--[if ") &&
tagText.endsWith("]")
+ if (tagText.startsWith("!--[if ") &&
tagText.endsWith("]")
&& this.input.getSubstring(pos + 3 -
12, pos + 3).equals("<![endif]-->"))
{
// fall through
@@ -219,17 +219,17 @@
{
// Get index of closing tag and advance past
the tag
closeBracketIndex = findCloseBracket('>', pos1);
-
+
if (closeBracketIndex == -1)
{
throw new ParseException("No matching
close bracket at position "
+ openBracketIndex,
this.input.getPosition());
}
-
+
// Get the tagtext between open and close
brackets
tagText =
this.input.getSubstring(openBracketIndex + 1, closeBracketIndex)
.toString();
-
+
pos1 = closeBracketIndex + 1;
}
while (tagText.endsWith("]]") == false);
@@ -302,9 +302,8 @@
}
else
{
- throw new ParseException("Malformed tag
(line "
- +
this.input.getLineNumber() + ", column "
- +
this.input.getColumnNumber() + ")", openBracketIndex);
+ throw new ParseException("Malformed tag
(line " + this.input.getLineNumber()
+ + ", column " +
this.input.getColumnNumber() + ")", openBracketIndex);
}
}
}
@@ -380,14 +379,21 @@
{
try
{
- this.xmlReader = new XmlReader(
- new
BufferedInputStream(resource.getInputStream(), 4000), encoding);
- this.input = new FullyBufferedReader(this.xmlReader);
+ xmlReader = new XmlReader(new
BufferedInputStream(resource.getInputStream(), 4000),
+ encoding);
+ input = new FullyBufferedReader(xmlReader);
}
finally
{
- resource.close();
- this.xmlReader.close();
+ // avoid NPEs by checking for null first
+ if (resource != null)
+ {
+ resource.close();
+ }
+ if (xmlReader != null)
+ {
+ xmlReader.close();
+ }
}
}