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 267922 - java.lang.NoSuchMethodError on compiled code. "Build Project" doesn't rebuild project correctly.
Summary: java.lang.NoSuchMethodError on compiled code. "Build Project" doesn't rebuild...
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Compiler (show other bugs)
Version: 8.1
Hardware: PC Linux
: P3 normal (vote)
Assignee: Dusan Balek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-07 11:31 UTC by Karabut
Modified: 2016-09-07 11:48 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Sample project (17.52 KB, application/zip)
2016-09-07 11:48 UTC, Karabut
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Karabut 2016-09-07 11:31:55 UTC
HOW TO REPRODUCE:

1. Create Java project with two classes:

org/sample/Main.java:
package org.sample;

public class HelloApplication {
    private static Greeter getGreeter() {
        return new Greeter(1);
    }
    
    public static void main(String[] args) throws Exception {
        getGreeter().greet();
    }
}


org/sample/Greeter.java:
package org.sample;

public class Greeter {
    public Greeter(int id) {}
    
    public void greet() {
        System.out.println("hello");
    }
}

2. Disable "Compile on save" feature.

3. Press "Run Project". Get expected "hello" output.

4. Change Greeter constructor signature Greeter(int id) -> Greeter(Integer id)
5. Press "Build Project". Only 1 class is compiled. Fragment from debug ant log:
fileset: Setup scanner in dir /home/viktor/NetBeansProjects/JavaApplication1/src with patternSet{ includes: [**] excludes: [] }
org/sample/Greeter.java added as org/sample/Greeter.class is outdated.
org/sample/HelloApplication.java omitted as /home/viktor/NetBeansProjects/JavaApplication1/build/classes/org/sample/HelloApplication.class is up to date.


6. Press "Run Project". Get runtime error:
Exception in thread "main" java.lang.NoSuchMethodError: org.sample.Greeter.<init>(Ljava/lang/Integer;)V
        at org.sample.HelloApplication.getGreeter(HelloApplication.java:14)
        at org.sample.HelloApplication.main(HelloApplication.java:18)
Comment 1 Karabut 2016-09-07 11:37:36 UTC
Reproducible even without "Compile on save" option:

2. Press "Build Project"
3. Run application from console
> java -jar dist/JavaApplication1.jar
hello
4. Change constructor Greeter(int id) -> Greeter(Integer id)
5. Press "Build Project"
6. Run application from console
> java -jar dist/JavaApplication1.jar
Exception in thread "main" java.lang.NoSuchMethodError: org.sample.Greeter.<init>(Ljava/lang/Integer;)V
        at org.sample.HelloApplication.getGreeter(HelloApplication.java:14)
        at org.sample.HelloApplication.main(HelloApplication.java:18)
Comment 2 Karabut 2016-09-07 11:44:02 UTC
Think, button "Build Project" should actually build project or at least compile all classes which call/refer to changed classes. Compiling of only changed *.java files results to broken project state.

I found only one old similar issue with "cannot reproduce" resolution: https://netbeans.org/bugzilla/show_bug.cgi?id=133683 

NetBeans About output:
Product Version: NetBeans IDE 8.1 (Build 201510222201)
Updates: NetBeans IDE is updated to version NetBeans 8.1 Patch 1
Java: 1.8.0_40; Java HotSpot(TM) 64-Bit Server VM 25.40-b25
Runtime: Java(TM) SE Runtime Environment 1.8.0_40-b25
System: Linux version 4.4.0-36-generic running on amd64; UTF-8; en_US (nb)
Comment 3 Karabut 2016-09-07 11:48:08 UTC
Created attachment 161945 [details]
Sample project