{"action":"created","issue":{"url":"https://api.github.com/repos/INRIA/spoon/issues/2483","repository_url":"https://api.github.com/repos/INRIA/spoon","labels_url":"https://api.github.com/repos/INRIA/spoon/issues/2483/labels{/name}","comments_url":"https://api.github.com/repos/INRIA/spoon/issues/2483/comments","events_url":"https://api.github.com/repos/INRIA/spoon/issues/2483/events","html_url":"https://github.com/INRIA/spoon/issues/2483","id":361787086,"node_id":"MDU6SXNzdWUzNjE3ODcwODY=","number":2483,"title":"bugs: bugs found with static analyzer PVS-Studio Java","user":{"login":"Egor18","id":32983915,"node_id":"MDQ6VXNlcjMyOTgzOTE1","avatar_url":"https://avatars2.githubusercontent.com/u/32983915?v=4","gravatar_id":"","url":"https://api.github.com/users/Egor18","html_url":"https://github.com/Egor18","followers_url":"https://api.github.com/users/Egor18/followers","following_url":"https://api.github.com/users/Egor18/following{/other_user}","gists_url":"https://api.github.com/users/Egor18/gists{/gist_id}","starred_url":"https://api.github.com/users/Egor18/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Egor18/subscriptions","organizations_url":"https://api.github.com/users/Egor18/orgs","repos_url":"https://api.github.com/users/Egor18/repos","events_url":"https://api.github.com/users/Egor18/events{/privacy}","received_events_url":"https://api.github.com/users/Egor18/received_events","type":"User","site_admin":false},"labels":[{"id":64529851,"node_id":"MDU6TGFiZWw2NDUyOTg1MQ==","url":"https://api.github.com/repos/INRIA/spoon/labels/bug","name":"bug","color":"fef2c0","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":9,"created_at":"2018-09-19T14:51:47Z","updated_at":"2018-09-25T13:53:09Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"Hello!\r\nI found several bugs in Spoon with our PVS-Studio Java static analyzer prototype.\r\n\r\n1.\r\nhttps://github.com/INRIA/spoon/blob/6b07da89021260f2222212ec1cd523ae9f4ec72f/src/main/java/spoon/support/visitor/ClassTypingContext.java#L218-L227 **Warning:** V6008 Null dereference of 'type'. ClassTypingContext.java:225\r\n\r\n2.\r\nhttps://github.com/INRIA/spoon/blob/97f6af6a14ba948050f087e205cc43d9b1516460/src/main/java/spoon/support/compiler/jdt/PositionBuilder.java#L691-L696 **Warning:** V6007 Expression 'content[off] == '\\n'' is always false. PositionBuilder.java:694\r\n\r\nProbably forgot to increment `off` here.\r\n\r\n3.\r\nhttps://github.com/INRIA/spoon/blob/8f14f3d0af5a21eef32a061224abbc786e7d3484/src/test/java/spoon/support/visitor/java/JavaReflectionTreeBuilderTest.java#L244-L245 **Warning:** V6009 Function 'equals' receives an odd argument. An object 'removeModifiers(elementModifiers, ModifierKind.PUBLIC, ModifierKind.ABSTRACT)' is used as an argument to its own method. JavaReflectionTreeBuilderTest.java:244\r\n\r\n\r\nhttps://github.com/INRIA/spoon/blob/8f14f3d0af5a21eef32a061224abbc786e7d3484/src/test/java/spoon/support/visitor/java/JavaReflectionTreeBuilderTest.java#L253-L254 **Warning:** V6009 Function 'equals' receives an odd argument. An object 'removeModifiers(elementModifiers, ModifierKind.PUBLIC)' is used as an argument to its own method. JavaReflectionTreeBuilderTest.java:253\r\n\r\nI'm pretty sure that `otherModifiers` (which is unused now) should be used here.\r\n\r\n4.\r\nhttps://github.com/INRIA/spoon/blob/88fe9031bca9d7c9cbb2103cb9e66ab5936760a9/src/main/java/spoon/metamodel/MMMethodKind.java#L114-L117 **Warning:** V6007 Expression 'result.level == k.level' is always false. MMMethodKind.java:115\r\n\r\nWe've already checked that `result.level < k.level`, how could it be `result.level == k.level`?\r\n\r\n5.\r\nhttps://github.com/INRIA/spoon/blob/267199348663afc9d94b8896ef9be714350a3d3a/src/main/java/spoon/support/reflect/declaration/CtEnumImpl.java#L115-L117 **Warning:** V6060 The 'enumValues' reference was utilized before it was verified against null. CtEnumImpl.java:117, CtEnumImpl.java:116\r\n\r\nhttps://github.com/INRIA/spoon/blob/79980e9ee7785f406115d7a07d44f20d8274add1/src/main/java/spoon/pattern/PatternBuilder.java#L116-L117 **Warning:** V6060 The 'template' reference was utilized before it was verified against null. PatternBuilder.java:117, PatternBuilder.java:116\r\n\r\nhttps://github.com/INRIA/spoon/blob/c020be3c28e95e1803abf79a63c8d9b1f649f203/src/main/java/spoon/support/compiler/jdt/ReferenceBuilder.java#L310-L312 **Warning:** V6060 The 'cuDeclaration' reference was utilized before it was verified against null. ReferenceBuilder.java:312, ReferenceBuilder.java:310\r\n\r\nThese checks for null make no sense, because we would get NRE earlier anyway.\r\n\r\n6.\r\nThere are lots of suspicious unused variables as well. Here is the list:\r\n**Warning:** V6021 Variable 'tpr' is not used. RoleHandlersGenerator.java:147\r\n**Warning:** V6021 Variable 'caseStmt' is not used. PositionBuilder.java:390\r\n**Warning:** V6021 Variable 'mapEntryNode' is not used. PatternParameterConfigurator.java:601\r\n**Warning:** V6021 Variable 'mmMethod' is not used. MetamodelProperty.java:112\r\n**Warning:** V6021 Variable 'executableTypeReference' is not used. JDTTreeBuilderHelper.java:240\r\n**Warning:** V6021 Variable 'executableFactory' is not used. JDTTreeBuilderHelper.java:190\r\n**Warning:** V6021 Variable 'typeFactory' is not used. JDTTreeBuilderHelper.java:188\r\n**Warning:** V6021 Variable 'innerClass' is not used. ImportScannerImpl.java:697\r\n**Warning:** V6021 Variable 'childSPI' is not used. ElementSourceFragment.java:184\r\n**Warning:** V6021 Variable 'sp' is not used. ElementSourceFragment.java:142\r\n"},"comment":{"url":"https://api.github.com/repos/INRIA/spoon/issues/comments/424352091","html_url":"https://github.com/INRIA/spoon/issues/2483#issuecomment-424352091","issue_url":"https://api.github.com/repos/INRIA/spoon/issues/2483","id":424352091,"node_id":"MDEyOklzc3VlQ29tbWVudDQyNDM1MjA5MQ==","user":{"login":"pvojtechovsky","id":23107345,"node_id":"MDQ6VXNlcjIzMTA3MzQ1","avatar_url":"https://avatars2.githubusercontent.com/u/23107345?v=4","gravatar_id":"","url":"https://api.github.com/users/pvojtechovsky","html_url":"https://github.com/pvojtechovsky","followers_url":"https://api.github.com/users/pvojtechovsky/followers","following_url":"https://api.github.com/users/pvojtechovsky/following{/other_user}","gists_url":"https://api.github.com/users/pvojtechovsky/gists{/gist_id}","starred_url":"https://api.github.com/users/pvojtechovsky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pvojtechovsky/subscriptions","organizations_url":"https://api.github.com/users/pvojtechovsky/orgs","repos_url":"https://api.github.com/users/pvojtechovsky/repos","events_url":"https://api.github.com/users/pvojtechovsky/events{/privacy}","received_events_url":"https://api.github.com/users/pvojtechovsky/received_events","type":"User","site_admin":false},"created_at":"2018-09-25T13:53:09Z","updated_at":"2018-09-25T13:53:09Z","author_association":"COLLABORATOR","body":"@Egor18 \r\nplease try this code as solution\r\n```java\r\n\tprivate CtTypeReference<?> getMethodParameterType(CtTypeReference<?> paramType) {\r\n\t\tif (paramType instanceof CtTypeParameterReference) {\r\n\t\t\tparamType = ((CtTypeParameterReference) paramType).getBoundingType();\r\n\t\t}\r\n\t\tif (paramType instanceof CtArrayTypeReference) {\r\n\t\t\tCtArrayTypeReference atr = (CtArrayTypeReference) paramType;\r\n\t\t\tCtTypeReference<?> originCT = atr.getComponentType();\r\n\t\t\tCtTypeReference<?> erasedCT = getMethodParameterType(originCT);\r\n\t\t\tif (originCT != erasedCT) {\r\n\t\t\t\tCtArrayTypeReference<?> erased = atr.clone();\r\n\t\t\t\terased.setComponentType(erasedCT);\r\n\t\t\t\treturn erased;\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (paramType == null) {\r\n\t\t\tparamType = factory.Type().OBJECT;\r\n\t\t}\r\n\t\treturn paramType.clone();\r\n\t}\r\n```"}}
{"actor":{"display_login":"pvojtechovsky"}}