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 250790 - inspect and transform does not work using import in custom hint
Summary: inspect and transform does not work using import in custom hint
Status: RESOLVED INVALID
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 8.0.2
Hardware: PC Windows 7
: P2 normal (vote)
Assignee: Svata Dedic
URL:
Keywords: REGRESSION
Depends on:
Blocks:
 
Reported: 2015-02-28 21:53 UTC by err
Modified: 2015-08-07 16:35 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
showing the setup (35.07 KB, image/png)
2015-03-06 20:30 UTC, err
Details

Note You need to log in before you can comment on or make changes to this bug.
Description err 2015-02-28 21:53:25 UTC
The following hint taken from NetBeans help "Syntax Rules for Declarative Hints" does not work. Note it appears that the mere presence of a custom import kills the hint, even when the import is not used; see ex 3.

======== FAIL ex 1 ===============
<?
    import java.util.LinkedList;
    import java.util.ArrayList;
?>

   new LinkedList()
=> new ArrayList()
;;
==================================


This hint does work.

======== WORKS ex 2 ==============
   new java.util.LinkedList()
=> new java.util.ArrayList()
;;
==================================


The following also fails. Note that this is the same as ex 2,
only a custom import section has been added.

======== FAIL ex 3 ===============
<?
    import java.util.Set;
?>

   new java.util.LinkedList()
=> new java.util.ArrayList()
;;
==================================
Comment 1 Svata Dedic 2015-03-06 13:05:13 UTC
I've tried in NB dev, copy pasted the FAIL ex 1, then typed a simple statement
List ll = new LinkedList();

The expression was underlined and the hint applied smoothly. What exactly is your code on which the hint does not work ? Do you use generics in the new expression ?
Comment 2 err 2015-03-06 20:29:34 UTC
I just tried it with a build I did a few days ago (see below). There's no
plugins (installed junit to get test project I'm working with OK) and a
fresh userdir, no changes made.  It fails, don't see any hint lightbulb.

I get "No Pattern Found" dialog. I'm attaching a png to show the setup.

Maybe there's some logging I can turn on?


Product Version: NetBeans IDE Dev (Build 20150302-90a1dce2ad09)
Updates: Updates available
Java: 1.8.0_31; Java HotSpot(TM) 64-Bit Server VM 25.31-b07
Runtime: Java(TM) SE Runtime Environment 1.8.0_31-b13
System: Windows 7 version 6.1 running on amd64; Cp1252; en_US (nb)
Comment 3 err 2015-03-06 20:30:37 UTC
Created attachment 152448 [details]
showing the setup
Comment 4 err 2015-03-06 20:37:04 UTC
Doh! I just reread your comment, where you asked if i used generics.

Yep, that's it.
Comment 5 err 2015-03-06 21:06:48 UTC
I haven't been able to find a bug about the generics. I also haven't been able to rewrite the hint to recognize generics (keep getting some exceptions).

Is it considered a bug? Is there an outstanding issue?
Comment 6 err 2015-03-07 01:01:22 UTC
Using a build I made today, with todays sources. NB dev can't handle these declarative hints. Starting with a clean userdir/cache, open a project with one source file:
    package debug;

    import java.util.LinkedList;

    public class NewClass {
        void foo() {
            LinkedList linkedList = new LinkedList();
        }
    }
do Refactor>InspectAndTransform>Browse>New...>EditScript
and paste "FAIL ex 1" in there. Get's an exception. Click save, an exception.
Click cancel, click cancel, close IDE.

The save actually occured.

    $ cat  /errw/AppData/Roaming/NetBeans/dev/config/rules/Inspection.hint
    <!description="Empty Inspection">
    <?
        import java.util.LinkedList;
        import java.util.ArrayList;
    ?>

       new LinkedList()
    => new ArrayList()
    ;;

Restarting the IDE, get many exceptions during startup, see below, and any
keystrokes in the editor (such as moving the cursor) produces exceptions.


INFO [org.openide.util.lookup.MetaInfServicesLookup]: Cannot create class org.netbeans.modules.java.hints.spiimpl.RulesManagerImpl
java.lang.ClassCastException: class com.sun.tools.javac.api.JavacTool
        at java.lang.Class.asSubclass(Class.java:3396)
        at javax.tools.ToolProvider.getSystemToolClass(ToolProvider.java:178)
        at javax.tools.ToolProvider.getSystemTool(ToolProvider.java:158)
        at javax.tools.ToolProvider.getSystemJavaCompiler(ToolProvider.java:102)
        at org.netbeans.modules.java.hints.declarative.Hacks.compile(Hacks.java:102)
        at org.netbeans.modules.java.hints.declarative.MethodInvocationContext.setCode(MethodInvocationContext.java:257)
        at org.netbeans.modules.java.hints.declarative.DeclarativeHintsParser$Impl.parseInput(DeclarativeHintsParser.java:188)
        ...
        at org.netbeans.modules.java.hints.spiimpl.RulesManagerImpl.reload(RulesManagerImpl.java:84)
        at org.netbeans.modules.java.hints.spiimpl.RulesManagerImpl.<init>(RulesManagerImpl.java:76)
        ...
[catch] at org.openide.util.lookup.MetaInfServicesLookup$Item.getInstance(MetaInfServicesLookup.java:514)
        ....

SEVERE [org.openide.util.Exceptions]
java.lang.NullPointerException
        at org.netbeans.modules.java.hints.spiimpl.hints.HintsInvoker.computeHints(HintsInvoker.java:154)
        ...
Comment 7 err 2015-03-07 01:03:44 UTC
I opened bug 250982 earlier, but now I'm confused and maybe both bugs aren't needed.
Comment 8 err 2015-03-07 01:13:06 UTC
I wrote the rule as
       new java.util.LinkedList<$any$>()
    => new java.util.ArrayList<$any$>()
    ;;
and it matches the generics.
Comment 9 err 2015-03-07 01:23:03 UTC
(In reply to err from comment #8)
This is generics on both on NB8.0.2 and nb-dev.

Also on NB8.0.2 I still can not get the <? import... ?> to work, with or without generics. 

And on nb-dev I can't seem to do anything with "<?" in it, as mentioned earlier, because of the exceptions.
Comment 10 Svata Dedic 2015-03-25 14:10:34 UTC
(In reply to err from comment #9)
> (In reply to err from comment #8)
> This is generics on both on NB8.0.2 and nb-dev.
> 
> Also on NB8.0.2 I still can not get the <? import... ?> to work, with or
> without generics. 
> 
> And on nb-dev I can't seem to do anything with "<?" in it, as mentioned
> earlier, because of the exceptions.


The <? import ?> section seems to work for me on dev builds, once issue #250982 was fixed. 

As <$any$> allows to match generic and two forms (non-generic + generic) of the hint can be entered - is the issue still valid ?
Comment 11 err 2015-03-25 16:05:03 UTC
Since issue #250982 has a fix for the import/custom-hint issues I'll dup this issue to it.

The generics, and using <$any$>, just confused the real issue when I was investigating.

*** This bug has been marked as a duplicate of bug 250982 ***
Comment 12 err 2015-04-01 14:33:37 UTC
(Guess it wasn't a duplicate after all)

(BTW, in messages.log about "malformed html" triggered by "<$any$>" are probably innocuous?)

Using a locally built NB.
Given the source file:

    package debug;

    import java.util.List;
    import java.util.LinkedList;

    public class NewClass {
        void foo() {
            List<String> linkedList = new LinkedList<>();

            List linkedList2 = new LinkedList();
        }
    }


=== This hint WORKS ===
$ cat /errw/AppData/Roaming/NetBeans/dev/config/rules/LinkedListToArray.hint
<!description="change LinkedList to ArrayList">

   new java.util.LinkedList<$any$>()
=> new java.util.ArrayList<$any$>()
;;

   new java.util.LinkedList()
=> new java.util.ArrayList()
;;
===========================


=== This hint DOES NOTHING ===
$ cat /errw/AppData/Roaming/NetBeans/dev/config/rules/LinkedListToArray.hint
<!description="change LinkedList to ArrayList">

<?
        import java.util.LinkedList;
        import java.util.ArrayList;
?>

   new LinkedList<$any$>()
=> new ArrayList<$any$>()
;;

   new LinkedList()
=> new ArrayList()
;;
===========================



Product Version: NetBeans IDE Dev (Build 20150401-09512dd8aa7b)
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-b26
System: Windows 7 version 6.1 running on amd64; Cp1252; en_US (nb)


$ hg log -r 5767ca601f74
changeset:   285322:5767ca601f74
user:        Svata Dedic <sdedic@netbeans.org>
date:        Wed Mar 25 14:11:34 2015 +0100
summary:     #250982: prevent loading JavacTool from JDK
Comment 13 err 2015-05-29 19:33:48 UTC
I just tried it again on Product Version: NetBeans IDE Dev (Build 201505280001)
(you never know...)
Comment 14 Svata Dedic 2015-08-07 16:35:49 UTC
Got it. The culprit is here:

    <!description="Empty Inspection">
    <?
        import java.util.LinkedList;
        import java.util.ArrayList;
    ?>


You have to put the processing instruction at the very top - the <!description must go after it. Other java blocks may be interleaved with rules and options, but imports must go first.