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 241755 - "clone() does not call super.clone()" hint does not support non-Object return type
Summary: "clone() does not call super.clone()" hint does not support non-Object return...
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 7.4
Hardware: All All
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-12 10:59 UTC by pepijn
Modified: 2014-02-21 10:38 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
A screenshot showing the problem in the latest nightly build (201402180001) (19.84 KB, image/png)
2014-02-18 10:58 UTC, pepijn
Details

Note You need to log in before you can comment on or make changes to this bug.
Description pepijn 2014-02-12 10:59:59 UTC
If the implementation of a clone() method does in fact invoke super.clone(), but super.clone() has a return type other than java.lang.Object, the "clone() does not call super.clone()" hint is erroneously displayed.

Example code:

public class A implements Cloneable {
    @Override
    public A clone() {
        try {
            return (A) super.clone();
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        }
    }
}

public class B extends A {
    @Override
    public B clone() { // "clone() does not call super.clone()" erroneously displayed on this line
        return (B) super.clone();
    }
}

A non-Object return type for clone() is allowed both by the rules of Java and the contract of clone(), and can be convenient (it can save casts in many places) so I think the hint should take it into account.
Comment 1 Svata Dedic 2014-02-17 16:31:47 UTC
Works for me fine in the current dev build.
Comment 2 pepijn 2014-02-18 10:58:04 UTC
Created attachment 145348 [details]
A screenshot showing the problem in the latest nightly build (201402180001)

As you can see from the screenshot I attached, the problem is still present in the latest nightly build (201402180001).
Comment 3 pepijn 2014-02-18 12:23:37 UTC
By the way, as you can also tell from the screenshot, the tooltip for the hint is also wrong. It says "clone() calls super.clone()", which should be "clone() does not call super.clone()" (even though of course in this case that is false). The hint should describe what is wrong (like the other hints do), not how it should be.
Comment 4 Svata Dedic 2014-02-18 13:47:30 UTC
I was kind of lazy and attempted to reproduce the defect on two nonpublic classes inside the same source. The hint does not appear in that situation - weird.
Reproduced on 2 toplevel public classes.
Comment 5 Svata Dedic 2014-02-18 16:51:06 UTC
In fact, the defect traces led to java.source module - getOverridenMethod() returned a synthetic bridge although a real method was available. So in your case, getOverridenMethod() returned Object clone() bridge present in A class, which was != from super.clone() (that resolved to A clone() method) and produced the suggestion.

Fixed in jet-main#e649a4e3f874

The reproduction is +- probabilistic ;) as it depends on ordering in class members hashtable buckets :)
Comment 6 Quality Engineering 2014-02-20 03:04:00 UTC
Integrated into 'main-silver', will be available in build *201402200001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/e649a4e3f874
User: Svata Dedic <sdedic@netbeans.org>
Log: #241755: favor real methods over synthetic bridges
Comment 7 pepijn 2014-02-21 10:38:10 UTC
I can confirm that the problem is indeed fixed in nightly build 201402200001. Thanks!