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 206141 - Inspect and Transform mysterious warnings/error dialog
Summary: Inspect and Transform mysterious warnings/error dialog
Status: VERIFIED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 7.1
Hardware: PC Mac OS X
: P2 normal (vote)
Assignee: Jan Lahoda
URL:
Keywords:
: 223829 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-12-08 14:19 UTC by twolf2919
Modified: 2012-12-27 20:56 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
warning dialog on inspect and transform (99.09 KB, image/tiff)
2011-12-08 14:19 UTC, twolf2919
Details
messages.log file with exception (65.75 KB, text/plain)
2011-12-09 14:17 UTC, twolf2919
Details

Note You need to log in before you can comment on or make changes to this bug.
Description twolf2919 2011-12-08 14:19:41 UTC
Created attachment 113956 [details]
warning dialog on inspect and transform

For some "Inspect and Transform" operations, I get a weird warning dialog (see attached image).  For instance, I just did a "Length one String in String.indexOf" inspect/transform and got mysterious "null" warnings on four files (out of some 4000 files inspected).

Either this is a bug in "Inspect and Transform" or just a terribly user unfriendly warning message.  Either way it should be addressed.
Comment 1 Jan Lahoda 2011-12-09 11:00:56 UTC
I am afraid that the stack trace of the exception is needed to evaluate - could you please attach {$nbuserdir}/var/log/messages.log? I hope the exceptions will be there. Thanks.
Comment 2 twolf2919 2011-12-09 14:16:32 UTC
Jan,
That's not a problem - since it happens every time.  Attached is the message.log file (I simply started up NB and ran the inspect/transform I mentioned and got the dialog.  Hope it helps.
Comment 3 twolf2919 2011-12-09 14:17:05 UTC
Created attachment 114004 [details]
messages.log file with exception
Comment 4 Jan Lahoda 2011-12-09 15:07:23 UTC
Thank you very much. Still not very clear to me what happens there (both by looking at the code and trying to run the transformation on all many projects I have open). There is probably something pretty specific in the code in the four files that is triggering this bug. It would be very helpful if you could try to enable hint (Tools/Options/Editor/Hints/Java/Performace/Length one String in String.indexOf), open one of the files and try whether/which of the warnings produces the exception (unfortunately, it will be necessary to actually perform the fix through Alt-Enter, the exception won't be thrown automatically in the editor). There will probably be something specific with the code that will trigger the bug. If you could share the constant value (the character value), or the overall structure of the String.indexOf/lastIndexOf call and surrounding code, that would be very helpful.

Thank you very much.
Comment 5 twolf2919 2011-12-09 15:43:13 UTC
Jan,
I opened the editor on one of the files with the editor hint enabled and get a ClassCastException when trying to do the hint replace on a very simple construct:
		if(!File.separator.equals("/")) {
See the exception below, followed by the bit of code that caused it, and a simple Test.java class that reproduces the problem independently.

Tom

java.lang.ClassCastException: com.sun.tools.javac.tree.JCTree$JCExpressionStatement cannot be cast to com.sun.source.tree.ExpressionTree
	at org.netbeans.modules.java.source.builder.TreeFactory.MethodInvocation(TreeFactory.java:406)
	at org.netbeans.modules.java.source.transform.ImmutableTreeTranslator.rewriteChildren(ImmutableTreeTranslator.java:902)
	at org.netbeans.modules.java.source.transform.ImmutableTreeTranslator.visitMethodInvocation(ImmutableTreeTranslator.java:427)
	at org.netbeans.modules.java.source.transform.ImmutableTreeTranslator.visitMethodInvocation(ImmutableTreeTranslator.java:92)
	at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1338)
	at org.netbeans.modules.java.source.transform.ImmutableTreeTranslator.translate(ImmutableTreeTranslator.java:134)
	at org.netbeans.api.java.source.TreeUtilities$1.translate(TreeUtilities.java:960)
	at org.netbeans.api.java.source.TreeUtilities.translate(TreeUtilities.java:969)
	at org.netbeans.api.java.source.WorkingCopy.processCurrentCompilationUnit(WorkingCopy.java:514)
	at org.netbeans.api.java.source.WorkingCopy.getChanges(WorkingCopy.java:672)
	at org.netbeans.api.java.source.JavaSource$1.run(JavaSource.java:668)
	at org.netbeans.api.java.source.JavaSource$1.run(JavaSource.java:655)
	at org.netbeans.api.java.source.JavaSource$MultiTask.run(JavaSource.java:482)
	at org.netbeans.modules.parsing.impl.TaskProcessor.callUserTask(TaskProcessor.java:643)
	at org.netbeans.modules.parsing.api.ParserManager$UserTaskAction.run(ParserManager.java:154)
	at org.netbeans.modules.parsing.api.ParserManager$UserTaskAction.run(ParserManager.java:138)
	at org.netbeans.modules.parsing.impl.TaskProcessor$2.call(TaskProcessor.java:211)
	at org.netbeans.modules.parsing.impl.TaskProcessor$2.call(TaskProcessor.java:208)
	at org.netbeans.modules.masterfs.filebasedfs.utils.FileChangedManager.priorityIO(FileChangedManager.java:168)
	at org.netbeans.modules.masterfs.providers.ProvidedExtensions.priorityIO(ProvidedExtensions.java:356)
	at org.netbeans.modules.parsing.impl.Utilities.runPriorityIO(Utilities.java:71)
	at org.netbeans.modules.parsing.impl.TaskProcessor.runUserTask(TaskProcessor.java:208)
	at org.netbeans.modules.parsing.api.ParserManager.parse(ParserManager.java:106)
	at org.netbeans.api.java.source.JavaSource.runUserActionTaskImpl(JavaSource.java:432)
	at org.netbeans.api.java.source.JavaSource.runUserActionTask(JavaSource.java:403)
	at org.netbeans.api.java.source.JavaSource.runModificationTask(JavaSource.java:676)
	at org.netbeans.modules.java.hints.jackpot.impl.JavaFixImpl.implement(JavaFixImpl.java:83)
[catch] at org.netbeans.modules.editor.hints.HintsUI$1.run(HintsUI.java:762)
	at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1411)
	at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:1991)

here's the bit of code with the indexOf() operation that caused the exception:
---------------------- 
	public String getAlarmNameForHelpText(String helpString) throws DataServiceException {
		String alarmName = null;
		if(!File.separator.equals("/")) {
-->			if(helpString.indexOf("\\") != -1)
			{
				helpString = helpString.replaceAll("\\\\","/" );
			}
		}
   ...
}

-----------------------------------

But it seems like you don't need a very complex example.  I see the same exception if I just write a simple Java  with that same construct:
public class Test {
	public Test() {
		System.err.println("Construct");
	}
	public void someMethod(String testString) {
		if (testString.indexOf("\\") != -1) {
			System.err.println("Hello world");
		}
	}
}
Comment 6 twolf2919 2011-12-09 15:46:08 UTC
Ooops - I meant that the very simple construct was:
    if (testString.indexOf("\\") != -1) {
an inadvertent bad copy/paste :-)

tom

(In reply to comment #5)
> Jan,
> I opened the editor on one of the files with the editor hint enabled and get a
> ClassCastException when trying to do the hint replace on a very simple
> construct:
>         if(!File.separator.equals("/")) {
> See the exception below, followed by the bit of code that caused it, and a
> simple Test.java class that reproduces the problem independently.
> 
> Tom
> 
> java.lang.ClassCastException:
> com.sun.tools.javac.tree.JCTree$JCExpressionStatement cannot be cast to
> com.sun.source.tree.ExpressionTree
>     at
> org.netbeans.modules.java.source.builder.TreeFactory.MethodInvocation(TreeFactory.java:406)
>     at
> org.netbeans.modules.java.source.transform.ImmutableTreeTranslator.rewriteChildren(ImmutableTreeTranslator.java:902)
>     at
> org.netbeans.modules.java.source.transform.ImmutableTreeTranslator.visitMethodInvocation(ImmutableTreeTranslator.java:427)
>     at
> org.netbeans.modules.java.source.transform.ImmutableTreeTranslator.visitMethodInvocation(ImmutableTreeTranslator.java:92)
>     at
> com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1338)
>     at
> org.netbeans.modules.java.source.transform.ImmutableTreeTranslator.translate(ImmutableTreeTranslator.java:134)
>     at
> org.netbeans.api.java.source.TreeUtilities$1.translate(TreeUtilities.java:960)
>     at
> org.netbeans.api.java.source.TreeUtilities.translate(TreeUtilities.java:969)
>     at
> org.netbeans.api.java.source.WorkingCopy.processCurrentCompilationUnit(WorkingCopy.java:514)
>     at
> org.netbeans.api.java.source.WorkingCopy.getChanges(WorkingCopy.java:672)
>     at org.netbeans.api.java.source.JavaSource$1.run(JavaSource.java:668)
>     at org.netbeans.api.java.source.JavaSource$1.run(JavaSource.java:655)
>     at
> org.netbeans.api.java.source.JavaSource$MultiTask.run(JavaSource.java:482)
>     at
> org.netbeans.modules.parsing.impl.TaskProcessor.callUserTask(TaskProcessor.java:643)
>     at
> org.netbeans.modules.parsing.api.ParserManager$UserTaskAction.run(ParserManager.java:154)
>     at
> org.netbeans.modules.parsing.api.ParserManager$UserTaskAction.run(ParserManager.java:138)
>     at
> org.netbeans.modules.parsing.impl.TaskProcessor$2.call(TaskProcessor.java:211)
>     at
> org.netbeans.modules.parsing.impl.TaskProcessor$2.call(TaskProcessor.java:208)
>     at
> org.netbeans.modules.masterfs.filebasedfs.utils.FileChangedManager.priorityIO(FileChangedManager.java:168)
>     at
> org.netbeans.modules.masterfs.providers.ProvidedExtensions.priorityIO(ProvidedExtensions.java:356)
>     at
> org.netbeans.modules.parsing.impl.Utilities.runPriorityIO(Utilities.java:71)
>     at
> org.netbeans.modules.parsing.impl.TaskProcessor.runUserTask(TaskProcessor.java:208)
>     at
> org.netbeans.modules.parsing.api.ParserManager.parse(ParserManager.java:106)
>     at
> org.netbeans.api.java.source.JavaSource.runUserActionTaskImpl(JavaSource.java:432)
>     at
> org.netbeans.api.java.source.JavaSource.runUserActionTask(JavaSource.java:403)
>     at
> org.netbeans.api.java.source.JavaSource.runModificationTask(JavaSource.java:676)
>     at
> org.netbeans.modules.java.hints.jackpot.impl.JavaFixImpl.implement(JavaFixImpl.java:83)
> [catch] at org.netbeans.modules.editor.hints.HintsUI$1.run(HintsUI.java:762)
>     at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1411)
>     at
> org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:1991)
> 
> here's the bit of code with the indexOf() operation that caused the exception:
> ---------------------- 
>     public String getAlarmNameForHelpText(String helpString) throws
> DataServiceException {
>         String alarmName = null;
>         if(!File.separator.equals("/")) {
> -->            if(helpString.indexOf("\\") != -1)
>             {
>                 helpString = helpString.replaceAll("\\\\","/" );
>             }
>         }
>    ...
> }
> 
> -----------------------------------
> 
> But it seems like you don't need a very complex example.  I see the same
> exception if I just write a simple Java  with that same construct:
> public class Test {
>     public Test() {
>         System.err.println("Construct");
>     }
>     public void someMethod(String testString) {
>         if (testString.indexOf("\\") != -1) {
>             System.err.println("Hello world");
>         }
>     }
> }
Comment 7 twolf2919 2011-12-09 15:51:11 UTC
Raising it to P2 as the code construct that causes the exception is very common and keeps this inspect/transform from being very useful in large projects.
Comment 8 Jan Lahoda 2011-12-09 15:58:13 UTC
Thank you very much for the test case, its easy to reproduce. Not sure offhand what is the cause, but I will take a deeper look soon.
Comment 9 Jan Lahoda 2011-12-09 19:17:57 UTC
Thank you again for you help. This should fix the problem:
http://hg.netbeans.org/jet-main/rev/7203c14d04af

Marking as a candidate to a 7.1 patch release.

If you see more of these problem (for other hints), please file them, I will be happy to fix them. Thanks.
Comment 10 Quality Engineering 2011-12-10 12:06:00 UTC
Integrated into 'main-golden'
Changeset: http://hg.netbeans.org/main-golden/rev/7203c14d04af
User: Jan Lahoda <jlahoda@netbeans.org>
Log: #206141: fixing handling of escapes while converting string literal of length one to char literal.
Comment 11 Jiri Prox 2011-12-12 12:52:36 UTC
verified


Product Version: NetBeans IDE Dev (Build 20111212-5a337de68bd3)
Java: 1.7.0_02; Java HotSpot(TM) Client VM 22.0-b10
System: Windows 7 version 6.1 running on x86; Cp1250; en_US (nb)
User directory: C:\Users\jprox\.netbeans\dev
Cache directory: C:\Users\jprox\.netbeans\dev\var\cache
Comment 12 Jan Lahoda 2012-01-09 14:59:39 UTC
release71_fixes:
http://hg.netbeans.org/releases/rev/4d5bc971302c
Comment 13 Jiri Prox 2012-02-13 15:55:07 UTC
verified in patch1
Comment 14 Jan Lahoda 2012-12-27 20:56:28 UTC
*** Bug 223829 has been marked as a duplicate of this bug. ***