Bug 268755 - ControlExample: possible NPE in Tab class
Summary: ControlExample: possible NPE in Tab class
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.5   Edit
Hardware: All All
: P3 trivial (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-03-16 07:27 EDT by Ivan Maidanski CLA
Modified: 2021-11-12 11:41 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ivan Maidanski CLA 2009-03-16 07:27:20 EDT
org.eclipse.swt.examples.controlexample.Tab.parameterInfo(String):
 returnType may be null:

                String typeName = null;
                Class returnType = getReturnType(methodRoot);
                boolean isArray = returnType.isArray();
                if (isArray) {
                        typeName = returnType.getComponentType().getName();
                } else {
                        typeName = returnType.getName();
                }

 possible solution: wrap this code into try/catch:

          Class returnType = getReturnType(methodRoot);
          String typeName;
          boolean isArray;
          try {
                isArray = returnType.isArray();
                if (isArray) {
                        typeName = returnType.getComponentType().getName();
                } else {
                        typeName = returnType.getName();
                }
          } catch (NullPointerException e) {
                isArray = false;
                typeName = "<<UnknownReturnType>>";
          }
Comment 1 Felipe Heidrich CLA 2009-03-16 10:28:55 EDT
do you have a case that fails ?
I believe that methodRoot always have a return type, otherwise it wouldn't be in the nameCombo control.


Ivan, are you using a tool to detect bugs in SWT ? Which one ?
Comment 2 Ivan Maidanski CLA 2009-03-16 12:30:07 EDT
> do you have a case that fails ?
> I believe that methodRoot always have a return type, otherwise it wouldn't be
> in the nameCombo control.

If an exception is caught in getReturnType() then it returns null. Why is try/catch present in getReturnType()?

I think this can't fail under normal conditions too. In my case I've obfuscated method names (I hadn't known that getters/setters are used by Tab) and pressed "Set/Get API" button, and got ControlExample termination due to NPE.

> 
> 
> Ivan, are you using a tool to detect bugs in SWT ? Which one ?

I'm experimenting with Java-to-C translation. Sometimes GCC complains about the code...
Comment 3 Steve Northover CLA 2009-03-16 12:45:36 EDT
> I'm experimenting with Java-to-C translation.

Very cool.
Comment 4 Eclipse Webmaster CLA 2019-09-06 16:07:52 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.