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 268214

Summary: Netbeans editor shows False errors (red) on Inherited field in Groovy from Java base class
Product: groovy Reporter: aplatypus <aplatypus>
Component: EditorAssignee: bruno.flavio
Status: NEW ---    
Severity: normal Keywords: JDK_8, USABILITY
Priority: P2    
Version: 8.2   
Hardware: PC   
OS: All   
Issue Type: DEFECT Exception Reporter:
Attachments: IDE log
Sample project

Description aplatypus 2016-09-27 00:55:59 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_102
Runtime = Java HotSpot(TM) 64-Bit Server VM 25.102-b14

Reproducibility: Happens every time


netbeans is showing errors for a protected static field from a Java base class.  

It is Not an error and the Groovy class runs correctly as a Unit Test with JUnit program.  However Netbeans insists there is an error.

Furthermore, the error shows ONLY in ONE method.  I made a dummy test that logs "Hello world" it does not show as an error.

When I past that exact line into the "public static" method, setUpClass() it shows an error on the lines:

      "  "  );
      testName +": ready."  );

Both LOG and testName are protected static member variables from the base class

When I change:

            public static void setUpClass(){...}    //   is STATIC

To be:

            public void setUpClass(){...}   //  Not  STATIC

The error goes away; clearly Netbeans 'thinks' that the static base class variables are NOT Static!!

This is wrong.  It wastes time looking at errors that are not errors in classes and on the project tree when we want to be doing productive work and running test cases. 

 We have to check in case there are  real errors to be fixed.  It is more than annoying, it is costing money in lost time and lost production.

  * There are several base classes with common code used in Testing with the database and server
  * Base class UnitTestingBase,  declares and initialises a Logger LOG as protected static
  * An intermediate class ServerTesting extends UnitTestingBase
  * A Groovy test class later extends ServerTesting
  * Add a dummy test @Test hello (not static)
  * Add a static test setup method: @BeforeClass setUpClass () // static
  * In both methods add the line:
      "hello world");

  An error shows in the project tree and in the file for the LOG use in the setUpClass method
  No error shows for the non-static Hello() method

  The Unit Test runs correctly and all logging lines are output.

  If I remove static from the set-up method, the error is NO LONGER reported

  No error state should show for the static method.

  I have an earlier Java  class that inherits from ServerTesting and the static setUpClass method in that class shows NO errors in Netbeans.

Samples of the classes described are given below.

I have closed Netbeans and restarted; the errors reappear.


Test class (Groovy):

   public abstract class FilterTest   extends   UnitTestingBase

        public FilterTest()
        {  }

        public static void setUpClass()
                String className = FilterTest.class.getSimpleName();

                ServerTesting.setUpClass(  TEST_ANNOTATION, className, FilterTest.class  );

      "  "  );
      testName +": ready."  );

        public void hello()
  "hello world");


Intermediate class (Java):

   public abstract class ServerTesting	extends	UnitTestingBase

        public ServerTesting()
       {  }


Base class (Java):

   abstract class UnitTestingBase
        //	available for every test-file
        protected static          Logger   LOG;
        protected static final  String     FIELD_ID	= "id";

        protected static         String      testName	= "(unknown)";
Comment 1 aplatypus 2016-09-27 00:56:08 UTC
Created attachment 162226 [details]
IDE log
Comment 2 aplatypus 2016-09-27 06:13:02 UTC
I tried changing the base classes to be Groovy classes.

I thought that might remove the issue.  It does NOT.  

Even when the sub-class class inherits from groovy parents the 

  protected static ...

Shows an error in a static void method()
Comment 3 aplatypus 2016-09-27 06:31:03 UTC
Firstly there's a typo in the example classes:

*  FilterTest extends ServerTesting	extends	UnitTestingBase

And not as shown below (initially), my apologies.

For the groovy base classes version, I used:

*  FilterTest extends ServerBddTesting	extends	UnitBddTestingBase

Unfortunately making the base classes into Groovy classes broke the test.

These Log messages below are printed by the (Groovy) base classes.

Tracking in the debugger, when the ServerBddTesting.setUpClass() call returns, there's a null pointer exception (as shown below).

Whereas when the FilterTest inherits from more or less the *same* classes written in Java all the code runs very happily.

At this point I definitely think the Groovy file using Java base classes is an error.  It looks like there is an incompatibility with the Groovy language and Java concerning what happens with protected fields/data.  One expects a "static protected XXX ..." declared item to be available in static scope for all child-classes in Most OO languages I've used.

Is this an anomaly or is that how it is supposed to function?


Testsuite: FilterTest
FilterTest DEBUG  : Log file configured from: '4ABS/'.
FilterTest INFO   : Unit testing: 4ABS Build: 1.14.0-dev (build: 005--SNAPSHOT ... BugGenie #173, #176)
FilterTest INFO   : Test label:   FilterTest - 1.14.0-dev (build: 005--SNAPSHOT ... BugGenie #173, #176), server-side
FilterTest INFO   : Test file:    FilterTest 

Testcase: FilterTest:	Caused an ERROR
Cannot invoke method info() on null object
java.lang.NullPointerException: Cannot invoke method info() on null object
	at org.codehaus.groovy.runtime.NullObject.invokeMethod(
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(
Comment 4 Jiri Kovalsky 2016-09-27 07:55:56 UTC
Reassigning for further evaluation.
Comment 5 tkellerer 2016-09-28 07:34:23 UTC
I have the same problem when trying to use the Moqui ( project sources in NetBeans. It e.g. has a Groovy class defined as :

    abstract class EntityFindBase

and then a Java class 

    public class EntityFindImpl extends EntityFindBase

For details of the implementation, you can see the source code here:

It's also not possible to jump from the Java class to the Groovy class (using e.g. "Goto Source" or "Goto Declaration")
Comment 6 bruno.flavio 2016-09-28 23:06:23 UTC
Created attachment 162261 [details]
Sample project

I've created a very simple project which I believe shows the problem stated in this issue. Could you please confirm?