merge changes that were not automatically discovered by Mercurial
diff --git a/src/main/java/org/yaml/snakeyaml/constructor/Constructor.java b/src/main/java/org/yaml/snakeyaml/constructor/Constructor.java
index a8bc0d3..cfe9878 100644
--- a/src/main/java/org/yaml/snakeyaml/constructor/Constructor.java
+++ b/src/main/java/org/yaml/snakeyaml/constructor/Constructor.java
@@ -9,6 +9,7 @@
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
+import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Date;
import java.util.HashMap;
@@ -153,7 +154,6 @@
}
return result;
}
-
}
@Override
@@ -241,17 +241,20 @@
java.lang.reflect.Constructor<?> constr = type.getConstructor(long.class);
result = constr.newInstance(date.getTime());
} catch (Exception e) {
- result = date;
+ throw new YAMLException("Cannot construct: '" + type + "'");
}
}
} else if (type == Float.class || type == Double.class || type == Float.TYPE
- || type == Double.TYPE) {
+ || type == Double.TYPE || type == BigDecimal.class) {
Construct doubleContructor = yamlConstructors.get("tag:yaml.org,2002:float");
result = doubleContructor.construct(node);
if (type == Float.class || type == Float.TYPE) {
result = new Float((Double) result);
+ } else if (type == BigDecimal.class) {
+ result = new BigDecimal(((Double) result).doubleValue());
}
- } else if (Number.class.isAssignableFrom(type) || type == Byte.TYPE
+ } else if (type == Byte.class || type == Short.class || type == Integer.class
+ || type == Long.class || type == BigInteger.class || type == Byte.TYPE
|| type == Short.TYPE || type == Integer.TYPE || type == Long.TYPE) {
Construct intContructor = yamlConstructors.get("tag:yaml.org,2002:int");
result = intContructor.construct(node);
@@ -263,10 +266,9 @@
result = new Integer(result.toString());
} else if (type == Long.class || type == Long.TYPE) {
result = new Long(result.toString());
- } else if (type == BigInteger.class) {
- result = new BigInteger(result.toString());
} else {
- throw new YAMLException("Unsupported Number class: " + type);
+ // only BigInteger left
+ result = new BigInteger(result.toString());
}
} else if (Enum.class.isAssignableFrom(type)) {
String tag = "tag:yaml.org,2002:" + type.getName();
@@ -342,9 +344,6 @@
boolean isArray = false;
try {
Property property = getProperty(beanType, key);
- if (property == null)
- throw new YAMLException("Unable to find property '" + key + "' on class: "
- + beanType.getName());
valueNode.setType(property.getType());
TypeDescription memberDescription = typeDefinitions.get(beanType);
if (memberDescription != null) {
@@ -388,23 +387,28 @@
return (T[]) Array.newInstance(type.getComponentType(), 0);
}
- protected Property getProperty(Class<? extends Object> type, String name)
+ private Property getProperty(Class<? extends Object> type, String name)
throws IntrospectionException {
for (PropertyDescriptor property : Introspector.getBeanInfo(type).getPropertyDescriptors()) {
if (property.getName().equals(name)) {
- if (property.getReadMethod() != null && property.getWriteMethod() != null)
+ if (property.getWriteMethod() != null) {
return new MethodProperty(property);
- break;
+ } else {
+ throw new YAMLException("Property '" + name + "' on JavaBean: "
+ + type.getName() + " does not have the write method");
+ }
}
}
for (Field field : type.getFields()) {
int modifiers = field.getModifiers();
- if (!Modifier.isPublic(modifiers) || Modifier.isStatic(modifiers)
- || Modifier.isTransient(modifiers))
+ if (Modifier.isStatic(modifiers) || Modifier.isTransient(modifiers)) {
continue;
- if (field.getName().equals(name))
+ }
+ if (field.getName().equals(name)) {
return new FieldProperty(field);
}
- return null;
+ }
+ throw new YAMLException("Unable to find property '" + name + "' on class: "
+ + type.getName());
}
}
diff --git a/src/main/java/org/yaml/snakeyaml/constructor/SafeConstructor.java b/src/main/java/org/yaml/snakeyaml/constructor/SafeConstructor.java
index 5296027..7ea30c4 100644
--- a/src/main/java/org/yaml/snakeyaml/constructor/SafeConstructor.java
+++ b/src/main/java/org/yaml/snakeyaml/constructor/SafeConstructor.java
@@ -223,12 +223,8 @@
}
return new Double(sign * val);
} else {
- try {
Double d = Double.valueOf(value);
return new Double(d.doubleValue() * sign);
- } catch (NumberFormatException e) {
- throw new YAMLException("Invalid number: '" + value + "'; in node " + node);
- }
}
}
}
@@ -263,7 +259,7 @@
} else {
match = TIMESTAMP_REGEXP.matcher((String) node.getValue());
if (!match.matches()) {
- throw new YAMLException("Expected timestamp: " + node);
+ throw new YAMLException("Unexpected timestamp: " + node.getValue());
}
String year_s = match.group(1);
String month_s = match.group(2);
@@ -293,20 +289,19 @@
cal.set(Calendar.MINUTE, Integer.parseInt(min_s));
cal.set(Calendar.SECOND, Integer.parseInt(sec_s));
cal.set(Calendar.MILLISECOND, usec);
- if (timezoneh_s != null || timezonem_s != null) {
+ if (timezoneh_s != null) {
int zone = 0;
int sign = +1;
- if (timezoneh_s != null) {
if (timezoneh_s.startsWith("-")) {
sign = -1;
}
zone += Integer.parseInt(timezoneh_s.substring(1)) * 3600000;
- }
if (timezonem_s != null) {
zone += Integer.parseInt(timezonem_s) * 60000;
}
cal.set(Calendar.ZONE_OFFSET, sign * zone);
} else {
+ // no time zone provided
cal.setTimeZone(TimeZone.getTimeZone("UTC"));
}
return cal.getTime();
diff --git a/src/main/java/org/yaml/snakeyaml/tokens/Token.java b/src/main/java/org/yaml/snakeyaml/tokens/Token.java
index a693d80..06edd31 100644
--- a/src/main/java/org/yaml/snakeyaml/tokens/Token.java
+++ b/src/main/java/org/yaml/snakeyaml/tokens/Token.java
@@ -4,6 +4,7 @@
package org.yaml.snakeyaml.tokens;
import org.yaml.snakeyaml.error.Mark;
+import org.yaml.snakeyaml.error.YAMLException;
/**
* @see <a href="http://pyyaml.org/wiki/PyYAML">PyYAML</a> for more information
@@ -14,7 +15,7 @@
public Token(Mark startMark, Mark endMark) {
if (startMark == null || endMark == null) {
- throw new NullPointerException("Token requires marks.");
+ throw new YAMLException("Token requires marks.");
}
this.startMark = startMark;
this.endMark = endMark;