This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 267960 - Class casting
Summary: Class casting
Status: NEW
Alias: None
Product: ide
Classification: Unclassified
Component: Code (show other bugs)
Version: 8.1
Hardware: PC Windows 10
: P3 normal (vote)
Assignee: issues@ide
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-09 21:08 UTC by henri127
Modified: 2016-09-09 21:24 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description henri127 2016-09-09 21:08:45 UTC
Product Version = NetBeans IDE 8.1 (Build 201510222201)
Operating System = Windows 10 version 10.0 running on amd64
Java; VM; Vendor = 1.8.0_72
Runtime = Java HotSpot(TM) 64-Bit Server VM 25.72-b15

Reproducibility: Happens every time

STEPS:
  * Open dialog Foo
  * Click on button "Click me"

ACTUAL:
  nothing happens

EXPECTED:
  message pops up


For a String Object in a class, which by reflection is accessible from the Field, return null when casted to int[][][][][], the rouitne used is from Class class

    /**
     * Casts an object to the class or interface represented
     * by this {@code Class} object.
     *
     * @param obj the object to be cast
     * @return the object after casting, or null if obj is null
     *
     * @throws ClassCastException if the object is not
     * null and is not assignable to the type T.
     *
     * @since 1.5
     */
    @SuppressWarnings("unchecked")
    public T cast(Object obj) {
        if (obj != null && !isInstance(obj))
            throw new ClassCastException(cannotCastMsg(obj));
        return (T) obj;
    }


thus:

public Class MyClass {

public String name;

public void function() {
	Field[] ff = getClass().getFields();
	if (ff != null) {
                        for (Field field : ff) {
                            try {
                                int[][][][][] fv = int[][][][][].class.cast(field.get(this));
                             } catch (ClassCastException e) {

                            }
                        }
	
	}
}

return in function for fv null when function is called, wheras the javadoc states a cast exception is thrown
Comment 1 henri127 2016-09-09 21:24:32 UTC
I think I made a mistake by reporting this, because the null pointer exception is thrown because the String is a null object, else the ClassCastException would be thrown.