You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gary D. Gregory (Jira)" <ji...@apache.org> on 2020/04/14 17:42:00 UTC

[jira] [Commented] (BCEL-336) MethodGen throws NullPointerException upon Invalid Class File Missing Constructor Body

    [ https://issues.apache.org/jira/browse/BCEL-336?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17083466#comment-17083466 ] 

Gary D. Gregory commented on BCEL-336:
--------------------------------------

What version of Apache Commons BCEL are you using?

> MethodGen throws NullPointerException upon Invalid Class File Missing Constructor Body
> --------------------------------------------------------------------------------------
>
>                 Key: BCEL-336
>                 URL: https://issues.apache.org/jira/browse/BCEL-336
>             Project: Commons BCEL
>          Issue Type: Task
>            Reporter: Tomo Suzuki
>            Priority: Major
>         Attachments: Screen Shot 2020-04-14 at 10.43.31.png
>
>
> MethodGen throws NullPointerException upon invalid class file missing constructor body. Should it throw more appropriate exception?
> {{javax:javaee-api:6.0}}'s {{javax.mail.internet.MailDateFormat}} does not have valid constructor body. When I tried to create MethodGen instance for the class, BCEL's MethodGen constructor throws NullPointerException:
> {code:java}
>       JavaClass sourceJavaClass = loadJavaClass(sourceClassName);
>       ClassGen classGen = new ClassGen(sourceJavaClass);
>       for (Method method : sourceJavaClass.getMethods()) {
>         MethodGen methodGen = new MethodGen(method, sourceClassName, classGen.getConstantPool());
>       ...
> {code}
> NullPointerException is thrown [https://github.com/GoogleCloudPlatform/cloud-opensource-java/issues/1352#issuecomment-613467921]
> The exception comes from {{new InstructionList(m.getCode().getCode()}}, where {{m.getCode()}} returning null.
> Given the class file is malformed (screenshot below), it's understandable for BCEL to throw an exception. Is there more appropriate exception (rather than NullPointerException)?
>   !Screen Shot 2020-04-14 at 10.43.31.png|width=857,height=504!



--
This message was sent by Atlassian Jira
(v8.3.4#803005)