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 - Netbeans editor shows False errors (red) on Inherited field in Groovy from Java base class
Summary: Netbeans editor shows False errors (red) on Inherited field in Groovy from Ja...
Status: NEW
Alias: None
Product: groovy
Classification: Unclassified
Component: Editor (show other bugs)
Version: 8.2
Hardware: PC All
: P2 normal with 2 votes (vote)
Assignee: bruno.flavio
URL:
Keywords: JDK_8, USABILITY
Depends on:
Blocks:
 
Reported: 2016-09-27 00:55 UTC by aplatypus
Modified: 2016-09-28 23:06 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
IDE log (242.47 KB, text/plain)
2016-09-27 00:56 UTC, aplatypus
Details
Sample project (4.47 KB, application/zip)
2016-09-28 23:06 UTC, bruno.flavio
Details

Note You need to log in before you can comment on or make changes to this bug.
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

ERROR:

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:

               LOG.info( "  "  );
               LOG.info( 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.


STEPS:
  * 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:
                LOG.info("hello world");

ACTUAL:
  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


EXPECTED:
  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()
        {  }

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

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

               LOG.info( "  "  );
               LOG.info( testName +": ready."  );
        }


        @Test
        public void hello()
        {
            LOG.info("hello world");
        }

  }//FilterTest


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/4ABS-testing-log4j.properties'.
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(NullObject.java:77)
	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
	at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:32)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
	at au.com.fourtel.fourabs.trip.TrainAdvancedFilterTest.setUpClass(TrainAdvancedFilterTest.groovy:43)
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 (http://www.moqui.org/) 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:

https://github.com/moqui/moqui-framework/tree/master/framework/src/main/groovy/org/moqui/impl/entity

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?


-Bruno