{"action":"created","issue":{"url":"https://api.github.com/repos/jboss-javassist/javassist/issues/80","repository_url":"https://api.github.com/repos/jboss-javassist/javassist","labels_url":"https://api.github.com/repos/jboss-javassist/javassist/issues/80/labels{/name}","comments_url":"https://api.github.com/repos/jboss-javassist/javassist/issues/80/comments","events_url":"https://api.github.com/repos/jboss-javassist/javassist/issues/80/events","html_url":"https://github.com/jboss-javassist/javassist/issues/80","id":156362698,"number":80,"title":"NullPointerException (NPE) in ArrayMemberValue in 3.18.1-GA","user":{"login":"Raymond-Naseef","id":3156904,"avatar_url":"https://avatars.githubusercontent.com/u/3156904?v=3","gravatar_id":"","url":"https://api.github.com/users/Raymond-Naseef","html_url":"https://github.com/Raymond-Naseef","followers_url":"https://api.github.com/users/Raymond-Naseef/followers","following_url":"https://api.github.com/users/Raymond-Naseef/following{/other_user}","gists_url":"https://api.github.com/users/Raymond-Naseef/gists{/gist_id}","starred_url":"https://api.github.com/users/Raymond-Naseef/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Raymond-Naseef/subscriptions","organizations_url":"https://api.github.com/users/Raymond-Naseef/orgs","repos_url":"https://api.github.com/users/Raymond-Naseef/repos","events_url":"https://api.github.com/users/Raymond-Naseef/events{/privacy}","received_events_url":"https://api.github.com/users/Raymond-Naseef/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2016-05-23T20:44:26Z","updated_at":"2016-06-10T13:11:52Z","closed_at":null,"body":"This happens whenever annotation contains member that is empty.  I can create test code to display this, but think the issue is probably simple, with solution be to check if field values is null.  This can be reproduced with javax.persistence.Table annotation.\r\n\r\njava.lang.NullPointerException: null\r\n\tat javassist.bytecode.annotation.ArrayMemberValue.write(ArrayMemberValue.java:133) ~[javassist-3.18.1-GA.jar:na]\r\n\tat javassist.bytecode.annotation.Annotation.write(Annotation.java:318) ~[javassist-3.18.1-GA.jar:na]\r\n\tat javassist.bytecode.AnnotationsAttribute.setAnnotations(AnnotationsAttribute.java:248) ~[javassist-3.18.1-GA.jar:na]\r\n\r\nHere is code causing the error, with workaround commented out that will avoid NPE:\r\n```\r\n\t\t\tAnnotation[] annotations = new Annotation[2];\r\n\t\t\tAnnotationsAttribute attrib =\r\n\t\t\t\t\tnew AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);\r\n\t\t\tAnnotation annotation = new Annotation(constPool, classPool.get(Entity.class.getName()));\r\n\t\t\tannotations[0] = annotation;\r\n\t\t\t// Add @Table(name=\"\",schema=\"\") to class\r\n\t\t\tannotation = new Annotation(constPool, classPool.get(Table.class.getName()));\r\n\t\t\tannotation.addMemberValue(\"name\", new StringMemberValue(dataTableName, constPool));\r\n\t\t\tannotation.addMemberValue(\"schema\", new StringMemberValue(dataSchema, constPool));\r\n\t\t\t// Add empty array to remove NPE at javassist.bytecode.annotation.ArrayMemberValue.write(ArrayMemberValue.java:133)\r\n\t\t\t// *** THIS FIX (workaround) NEEDS UNCOMMENTING THESE 4 LINES\r\n//\t\t\tArrayMemberValue blankMemberValueArray = new ArrayMemberValue(new AnnotationMemberValue(constPool), constPool);\r\n//\t\t\tblankMemberValueArray.setValue(new MemberValue[0]);\r\n//\t\t\tannotation.addMemberValue(\"uniqueConstraints\", blankMemberValueArray);\r\n//\t\t\tannotation.addMemberValue(\"indexes\", blankMemberValueArray);\r\n\t\t\tannotations[1] = annotation;\r\n\t\t\tattrib.setAnnotations(annotations);\r\n\t\t\tctFile.addAttribute(attrib);\r\n\r\n```"},"comment":{"url":"https://api.github.com/repos/jboss-javassist/javassist/issues/comments/225178007","html_url":"https://github.com/jboss-javassist/javassist/issues/80#issuecomment-225178007","issue_url":"https://api.github.com/repos/jboss-javassist/javassist/issues/80","id":225178007,"user":{"login":"Raymond-Naseef","id":3156904,"avatar_url":"https://avatars.githubusercontent.com/u/3156904?v=3","gravatar_id":"","url":"https://api.github.com/users/Raymond-Naseef","html_url":"https://github.com/Raymond-Naseef","followers_url":"https://api.github.com/users/Raymond-Naseef/followers","following_url":"https://api.github.com/users/Raymond-Naseef/following{/other_user}","gists_url":"https://api.github.com/users/Raymond-Naseef/gists{/gist_id}","starred_url":"https://api.github.com/users/Raymond-Naseef/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Raymond-Naseef/subscriptions","organizations_url":"https://api.github.com/users/Raymond-Naseef/orgs","repos_url":"https://api.github.com/users/Raymond-Naseef/repos","events_url":"https://api.github.com/users/Raymond-Naseef/events{/privacy}","received_events_url":"https://api.github.com/users/Raymond-Naseef/received_events","type":"User","site_admin":false},"created_at":"2016-06-10T13:11:51Z","updated_at":"2016-06-10T13:11:51Z","body":"Here is code causing the error:\r\n\r\n\r\n```\r\n\r\nimport javassist.*;\r\nimport javassist.bytecode.*;\r\nimport javassist.bytecode.annotation.*;\r\n\r\n@interface Entity {}\r\n\r\n@interface Table { String[] textValues() default {}; }\r\n\r\npublic class Test {\r\n    public static void main(String[] args) throws Exception {\r\n        ClassPool classPool = ClassPool.getDefault();\r\n        ClassFile cf = classPool.makeClass(\"TestSub\").getClassFile();\r\n        ConstPool constPool = cf.getConstPool();\r\n        Annotation[] annotations = new Annotation[2];\r\n        AnnotationsAttribute attrib =\r\n                new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);\r\n        Annotation annotation = new Annotation(constPool, classPool.get(\"Entity\"));\r\n        annotations[0] = annotation;\r\n        // Add @Table(name=\"\",schema=\"\") to class\r\n        annotation = new Annotation(constPool, classPool.get(\"Table\"));\r\n        annotation.addMemberValue(\"name\", new StringMemberValue(\"name\", constPool));\r\n        annotation.addMemberValue(\"schema\", new StringMemberValue(\"schema\", constPool));\r\n//        ArrayMemberValue blankMemberValueArray = new ArrayMemberValue(new AnnotationMemberValue(constPool), constPool);\r\n//        blankMemberValueArray.setValue(new MemberValue[0]);\r\n//        annotation.addMemberValue(\"textValues\", blankMemberValueArray);\r\n        annotations[1] = annotation;\r\n        attrib.setAnnotations(annotations);\r\n        cf.addAttribute(attrib);\r\n    }\r\n}\r\n```"}}
{"actor":{"display_login":"Raymond-Naseef"}}