فهرست منبع

[java] don't NPE on `null` in `Relfect.getProperty()` (fixes #4934)

Aleksandr Kuzmenko 6 سال پیش
والد
کامیت
9ca28275c5
2فایلهای تغییر یافته به همراه5 افزوده شده و 2 حذف شده
  1. 3 0
      std/java/_std/Reflect.hx
  2. 2 2
      tests/unit/src/unitstd/Reflect.unit.hx

+ 3 - 0
std/java/_std/Reflect.hx

@@ -56,6 +56,9 @@ import java.Boot;
 
 	public static function getProperty( o : Dynamic, field : String ) : Dynamic
 	{
+		if (o == null || field == null) {
+			return null;
+		}
 		if (Std.is(o, IHxObject)) {
 			return untyped (o : IHxObject).__hx_getField(field, false, false, true);
 		}

+ 2 - 2
tests/unit/src/unitstd/Reflect.unit.hx

@@ -37,8 +37,8 @@ Reflect.getProperty(c, "v") == "var";
 Reflect.getProperty(c, "prop") == "prop";
 Reflect.getProperty(c, "func")() == "foo";
 Reflect.getProperty(c, "propAcc") == "1";
-//Reflect.getProperty(null, "a") == null;
-//Reflect.getProperty(null, null) == null;
+Reflect.getProperty(null, "a") == null;
+Reflect.getProperty(null, null) == null;
 
 // setProperty
 Reflect.setProperty(x, "a", 2);