{"action":"created","issue":{"url":"https://api.github.com/repos/Unidata/thredds/issues/507","repository_url":"https://api.github.com/repos/Unidata/thredds","labels_url":"https://api.github.com/repos/Unidata/thredds/issues/507/labels{/name}","comments_url":"https://api.github.com/repos/Unidata/thredds/issues/507/comments","events_url":"https://api.github.com/repos/Unidata/thredds/issues/507/events","html_url":"https://github.com/Unidata/thredds/issues/507","id":144935944,"number":507,"title":"Write attribute value of type Object[]","user":{"login":"r0perice","id":7713432,"avatar_url":"https://avatars.githubusercontent.com/u/7713432?v=3","gravatar_id":"","url":"https://api.github.com/users/r0perice","html_url":"https://github.com/r0perice","followers_url":"https://api.github.com/users/r0perice/followers","following_url":"https://api.github.com/users/r0perice/following{/other_user}","gists_url":"https://api.github.com/users/r0perice/gists{/gist_id}","starred_url":"https://api.github.com/users/r0perice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/r0perice/subscriptions","organizations_url":"https://api.github.com/users/r0perice/orgs","repos_url":"https://api.github.com/users/r0perice/repos","events_url":"https://api.github.com/users/r0perice/events{/privacy}","received_events_url":"https://api.github.com/users/r0perice/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Unidata/thredds/labels/Area:%20NetCDF-Java","name":"Area: NetCDF-Java","color":"c7def8"},{"url":"https://api.github.com/repos/Unidata/thredds/labels/Type:%20Bug","name":"Type: Bug","color":"f7c6c7"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-03-31T15:34:39Z","updated_at":"2016-03-31T16:08:33Z","closed_at":null,"body":"Hello,\r\n\r\nI Have troubles writting Attributes in Java (v4.6.4). \r\n\r\n* Who I read the attribute values :\r\n\r\n```java\r\n final boolean isArray = attribute.isArray();\r\n        if (isArray) {\r\n            final Array attrValues = attribute.getValues();\r\n            value = attrValues.copyTo1DJavaArray();\r\n        } else {\r\n            value = attrFirstValue;\r\n        }\r\n```\r\n* How I write the attribute :\r\n\r\n```java\r\nattr = new Attribute(name, Array.factory(values));\r\nwriter.addVariableAttribute(variable, attr);\r\n```\r\nThis works with `short[]` and `byte[]` but I have a problem with `Object[]` :\r\n\r\n> FAILED: netcdfOutputTest\r\njava.lang.NullPointerException\r\n\tat ucar.ma2.Array.**reflectArrayCopyIn**(Array.java:259)\r\n\tat ucar.ma2.Array.reflectArrayCopyIn(Array.java:263)\r\n\tat ucar.ma2.Array.factory(Array.java:252)\r\n\r\nIn the method **reflectArratCopyIn()**\r\n\r\n```java\r\nstatic private void reflectArrayCopyIn(Object jArray, Array aa, IndexIterator aaIter) {\r\n    Class cType = jArray.getClass().getComponentType();\r\n    if (cType.isPrimitive()) {\r\n      aa.copyFrom1DJavaArray(aaIter, jArray);  // subclass does type-specific copy\r\n    } else {\r\n      for (int i = 0; i < java.lang.reflect.Array.getLength(jArray); i++)  // recurse\r\n        reflectArrayCopyIn(java.lang.reflect.Array.get(jArray, i), aa, aaIter);\r\n    }\r\n  }\r\n```\r\nThe call `jArray.getClass().getComponentType();` returns `null` for `Object[]`.\r\n\r\nIs their another method to use in my case ? In fact my `Object[]` is a `String[]` \r\n\r\nAny help will be greatly appreciated :+1: \r\n\r\nRegards,\r\n\r\nRobin\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/Unidata/thredds/issues/comments/204002699","html_url":"https://github.com/Unidata/thredds/issues/507#issuecomment-204002699","issue_url":"https://api.github.com/repos/Unidata/thredds/issues/507","id":204002699,"user":{"login":"lesserwhirls","id":67096,"avatar_url":"https://avatars.githubusercontent.com/u/67096?v=3","gravatar_id":"","url":"https://api.github.com/users/lesserwhirls","html_url":"https://github.com/lesserwhirls","followers_url":"https://api.github.com/users/lesserwhirls/followers","following_url":"https://api.github.com/users/lesserwhirls/following{/other_user}","gists_url":"https://api.github.com/users/lesserwhirls/gists{/gist_id}","starred_url":"https://api.github.com/users/lesserwhirls/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lesserwhirls/subscriptions","organizations_url":"https://api.github.com/users/lesserwhirls/orgs","repos_url":"https://api.github.com/users/lesserwhirls/repos","events_url":"https://api.github.com/users/lesserwhirls/events{/privacy}","received_events_url":"https://api.github.com/users/lesserwhirls/received_events","type":"User","site_admin":false},"created_at":"2016-03-31T16:08:33Z","updated_at":"2016-03-31T16:08:33Z","body":"Greetings @r0perice,\r\n\r\nThis is a bug, for sure. The javadoc for `Array.factory` for input of an `Object[]` has a [comment](https://www.unidata.ucar.edu/software/thredds/current/netcdf-java/javadoc/ucar/ma2/Array.html#factory-java.lang.Object-) that says:\r\n\r\n```\r\nLOOK: not sure this works for reference types.\r\n```\r\n\r\nand, well, sure enough, it doesn't.\r\n\r\nThanks for the detailed report!"}}