1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-22 22:32:06 +01:00

Throw more exceptions when parsing Presences

when parsing core elements of Presences.
This commit is contained in:
Florian Schmaus 2014-06-10 18:40:15 +02:00
parent 009057e2e2
commit b083449cc3

View file

@ -259,12 +259,7 @@ public class PacketParserUtils {
Presence.Type type = Presence.Type.available; Presence.Type type = Presence.Type.available;
String typeString = parser.getAttributeValue("", "type"); String typeString = parser.getAttributeValue("", "type");
if (typeString != null && !typeString.equals("")) { if (typeString != null && !typeString.equals("")) {
try { type = Presence.Type.fromString(typeString);
type = Presence.Type.fromString(typeString);
}
catch (IllegalArgumentException iae) {
LOGGER.warning("Found invalid presence type " + typeString);
}
} }
Presence presence = new Presence(type); Presence presence = new Presence(type);
presence.setTo(parser.getAttributeValue("", "to")); presence.setTo(parser.getAttributeValue("", "to"));
@ -289,32 +284,20 @@ public class PacketParserUtils {
presence.setStatus(parser.nextText()); presence.setStatus(parser.nextText());
} }
else if (elementName.equals("priority")) { else if (elementName.equals("priority")) {
try { int priority = Integer.parseInt(parser.nextText());
int priority = Integer.parseInt(parser.nextText()); presence.setPriority(priority);
presence.setPriority(priority);
}
catch (NumberFormatException nfe) {
// Ignore.
}
catch (IllegalArgumentException iae) {
// Presence priority is out of range so assume priority to be zero
presence.setPriority(0);
}
} }
else if (elementName.equals("show")) { else if (elementName.equals("show")) {
String modeText = parser.nextText(); String modeText = parser.nextText();
try { presence.setMode(Presence.Mode.fromString(modeText));
presence.setMode(Presence.Mode.fromString(modeText));
}
catch (IllegalArgumentException iae) {
LOGGER.warning("Found invalid presence mode " + modeText);
}
} }
else if (elementName.equals("error")) { else if (elementName.equals("error")) {
presence.setError(parseError(parser)); presence.setError(parseError(parser));
} }
// Otherwise, it must be a packet extension. // Otherwise, it must be a packet extension.
else { else {
// Be extra robust: Skip PacketExtensions that cause Exceptions, instead of
// failing completely here. See SMACK-390 for more information.
try { try {
presence.addExtension(PacketParserUtils.parsePacketExtension(elementName, namespace, parser)); presence.addExtension(PacketParserUtils.parsePacketExtension(elementName, namespace, parser));
} }