{"action":"created","issue":{"url":"https://api.github.com/repos/wpilibsuite/ntcore/issues/72","repository_url":"https://api.github.com/repos/wpilibsuite/ntcore","labels_url":"https://api.github.com/repos/wpilibsuite/ntcore/issues/72/labels{/name}","comments_url":"https://api.github.com/repos/wpilibsuite/ntcore/issues/72/comments","events_url":"https://api.github.com/repos/wpilibsuite/ntcore/issues/72/events","html_url":"https://github.com/wpilibsuite/ntcore/issues/72","id":160745467,"number":72,"title":"Add support for adding any number value","user":{"login":"SamCarlberg","id":6320992,"avatar_url":"https://avatars.githubusercontent.com/u/6320992?v=3","gravatar_id":"","url":"https://api.github.com/users/SamCarlberg","html_url":"https://github.com/SamCarlberg","followers_url":"https://api.github.com/users/SamCarlberg/followers","following_url":"https://api.github.com/users/SamCarlberg/following{/other_user}","gists_url":"https://api.github.com/users/SamCarlberg/gists{/gist_id}","starred_url":"https://api.github.com/users/SamCarlberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SamCarlberg/subscriptions","organizations_url":"https://api.github.com/users/SamCarlberg/orgs","repos_url":"https://api.github.com/users/SamCarlberg/repos","events_url":"https://api.github.com/users/SamCarlberg/events{/privacy}","received_events_url":"https://api.github.com/users/SamCarlberg/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-06-16T19:52:14Z","updated_at":"2016-06-17T02:53:38Z","closed_at":null,"body":"Right now, calls to `putValue` with a float value (and I suspect `Integer` as well) cause an `IllegalArgumentException` to be thrown.\r\n\r\nLines 722 and 723 in `NetworkTable.putValue(String, Object)` could be changed to the following bolded lines.\r\n\r\n<pre>\r\n  @Override\r\n  public boolean putValue(String key, Object value) throws IllegalArgumentException {\r\n    if (value instanceof Boolean)\r\n      return NetworkTablesJNI.putBoolean(path + PATH_SEPARATOR + key, ((Boolean)value).booleanValue());\r\n    <b>else if (value instanceof Number)\r\n      return NetworkTablesJNI.putDouble(path + PATH_SEPARATOR + key, ((Number)value).doubleValue());</b>\r\n    ... // Ommitted for brevity\r\n</pre>\r\n\r\nSimilarly, `putNumber(String, double)` could be overloaded with a `putNumber(String, Number)` that would just delegate to the first method:\r\n```\r\npublic void putNumber(String key, Number value) {\r\n  putNumber(key, value.doubleValue());\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/wpilibsuite/ntcore/issues/comments/226668381","html_url":"https://github.com/wpilibsuite/ntcore/issues/72#issuecomment-226668381","issue_url":"https://api.github.com/repos/wpilibsuite/ntcore/issues/72","id":226668381,"user":{"login":"SamCarlberg","id":6320992,"avatar_url":"https://avatars.githubusercontent.com/u/6320992?v=3","gravatar_id":"","url":"https://api.github.com/users/SamCarlberg","html_url":"https://github.com/SamCarlberg","followers_url":"https://api.github.com/users/SamCarlberg/followers","following_url":"https://api.github.com/users/SamCarlberg/following{/other_user}","gists_url":"https://api.github.com/users/SamCarlberg/gists{/gist_id}","starred_url":"https://api.github.com/users/SamCarlberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SamCarlberg/subscriptions","organizations_url":"https://api.github.com/users/SamCarlberg/orgs","repos_url":"https://api.github.com/users/SamCarlberg/repos","events_url":"https://api.github.com/users/SamCarlberg/events{/privacy}","received_events_url":"https://api.github.com/users/SamCarlberg/received_events","type":"User","site_admin":false},"created_at":"2016-06-17T02:53:38Z","updated_at":"2016-06-17T02:53:38Z","body":"It's mostly to do with `putValue`. I suggested a `putNumber` overload to offer a more explicit function, but I don't think it needs to be added.\r\n\r\nYes, `putValue(\"key\", 1)` will throw an `IllegalArgumentException`.\r\n\r\nThe issue with it is that it only checks for `value instanceof Double`. It doesn't check for `Integer` (or any smaller integer type like `Short` or `Byte`), nor does it check for `Float`, which can be safely cast to `Double` without losing precision. (`putNumber(key, float)` *does* work, though, due to the compiler promoting `float` to `double`). The safest way would be to change the check from\r\n```\r\nif (value instanceof Double)\r\n```\r\nto\r\n```\r\nif (value instanceof Byte || value instanceof Character || value instanceof Short || value instanceof Integer || value instanceof Float || value instanceof Double)\r\n```\r\n\r\nSince that only excludes `Long` (and `BigInteger`, which I doubt would be used by a user), that big `if` could be\r\n```\r\nif (value instanceof Number && !(value instanceof Long))\r\n```\r\n\r\nAdditionally, the exception message could be better. Something like:\r\n```\r\nthrow new IllegalArgumentException(\"Value of type \" + value.getClass().getName() + \" cannot be put into a table\");\r\n```"}}
{"actor":{"display_login":"SamCarlberg"}}