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 224930 - IDE generates uncompilable code
Summary: IDE generates uncompilable code
Status: RESOLVED WORKSFORME
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 7.2.1
Hardware: All Linux
: P2 normal (vote)
Assignee: Jan Lahoda
URL:
Keywords: REGRESSION
Depends on:
Blocks:
 
Reported: 2013-01-15 19:52 UTC by _ tboudreau
Modified: 2013-01-15 23:53 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 _ tboudreau 2013-01-15 19:52:10 UTC
For the last few months, the Implement Abstract Methods hint has generated "return null;" inside methods whose return type is "void".  I thought this was an obvious bug that would be fixed quickly, but it appears it has not.

To reproduce:

Define an interface
public interface Foo {
   void foo();
}

and an implementation

public class FooImpl implements Foo {
}

Accept the hint on the class declaration line and you get

public class FooImpl implements Foo {
    public void foo() {
      return null;
    }
}

which is completely unusable. How much do you trust the IDE if you have to fix many such methods?  A // TODO comment would make sense;  a throw UnsupportedOperationException() is ugly but would make sense;  the current behavior is 100% guaranteed to be wrong for everybody.
Comment 1 Jan Lahoda 2013-01-15 21:13:20 UTC
Sorry, but not for me. For me, it generates:
     @Override
     public void test() {
          throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
     }

Could you please check what you have in Tools/Templates/Java/Code Snippets/Generated Method Body? The default content is available here:
http://hg.netbeans.org/releases/file/release73/java.source/src/org/netbeans/modules/java/source/resources/OverriddenMethodBody.template

Thanks.
Comment 2 _ tboudreau 2013-01-15 23:53:24 UTC
Really strange - I have never edited this template.  But it is a userdir I have been using for a very long time, so something may have touched it...