Tomo Suzuki created BCEL-336:
--------------------------------

             Summary: 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
         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)

Reply via email to