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 203540 - [71cat] ClassCastException: class com.sun.tools.javac.api.JavacTool
Summary: [71cat] ClassCastException: class com.sun.tools.javac.api.JavacTool
Status: RESOLVED WONTFIX
Alias: None
Product: java
Classification: Unclassified
Component: Compiler (show other bugs)
Version: 7.0
Hardware: All All
: P3 normal (vote)
Assignee: Dusan Balek
URL:
Keywords:
: 204071 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-10-11 17:15 UTC by sunbiz
Modified: 2015-09-17 11:25 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter: 181893


Attachments
stacktrace (802 bytes, text/plain)
2011-10-11 17:15 UTC, sunbiz
Details

Note You need to log in before you can comment on or make changes to this bug.
Description sunbiz 2011-10-11 17:15:46 UTC
Build: NetBeans IDE Dev (Build 201110100600)
VM: Java HotSpot(TM) 64-Bit Server VM, 20.2-b06, Java(TM) SE Runtime Environment, 1.6.0_27-b07
OS: Windows 7

User Comments:
sunbiz: Created POJO and Hibernate Mapping Files from database,  Run HQL Query on Hibernate configuration file and got this exception




Stacktrace: 
java.lang.ClassCastException: class com.sun.tools.javac.api.JavacTool
   at java.lang.Class.asSubclass(Class.java:3018)
   at javax.tools.ToolProvider.getSystemToolClass(ToolProvider.java:165)
   at javax.tools.ToolProvider.getSystemTool(ToolProvider.java:145)
   at javax.tools.ToolProvider.getSystemJavaCompiler(ToolProvider.java:102)
   at org.netbeans.modules.hibernate.hqleditor.HQLEditorController.checkAndCompile(HQLEditorController.java:681)
   at org.netbeans.modules.hibernate.hqleditor.HQLEditorController.processMatchingClass(HQLEditorController.java:664)
Comment 1 sunbiz 2011-10-11 17:15:52 UTC
Created attachment 111880 [details]
stacktrace
Comment 2 Sergey Petrov 2011-10-24 11:22:13 UTC
*** Bug 204071 has been marked as a duplicate of this bug. ***
Comment 3 Sergey Petrov 2011-10-25 11:30:38 UTC
Looks like nb javac issue, as it's just call to ToolProvider.getSystemJavaCompiler().
But feel free to push back for more investigation.
Comment 4 Jan Lahoda 2011-11-16 09:28:40 UTC
Hm, I would be happier if noone (except java.source) wouldn't use nb-javac for compiling - using the platform's javac should be much safer. But it is currently not possible to use the Java infrastructure and the platform's javac in one module. I guess we need to find a way out from this.

In the mean time, a workaround is to wrap the invocation of ToolProvider.getSystemJavaCompiler with:
        ClassLoader orig = Thread.currentThread().getContextClassLoader();
        try {
Thread.currentThread().setContextClassLoader(ClasspathInfo.class.getClassLoader());
            JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
        } finally {
            Thread.currentThread().setContextClassLoader(orig);
        }

I would recommend using this workaround for 7.1 - it depends on a non-guaranteed implementation detail, but should work, and we will have more time to come up with a real solution.

Sorry for the trouble.
Comment 5 Sergey Petrov 2011-11-16 12:07:21 UTC
Jan, thanks,
http://hg.netbeans.org/web-main/rev/e3e13e0a83c0 workaround.

do you want this issue to remain open?
Comment 6 Jan Lahoda 2011-11-16 14:05:55 UTC
(In reply to comment #5)
> Jan, thanks,
> http://hg.netbeans.org/web-main/rev/e3e13e0a83c0 workaround.

Thanks.

> 
> do you want this issue to remain open?

Yes, please.
Comment 7 Quality Engineering 2011-11-17 07:31:17 UTC
Integrated into 'main-golden'
Changeset: http://hg.netbeans.org/main-golden/rev/e3e13e0a83c0
User: Sergey B. Petrov <sj-nb@netbeans.org>
Log: #203540 implemet suggested workaround
Comment 8 Exceptions Reporter 2012-02-14 09:24:59 UTC
This bug already has 5 duplicates 
see http://statistics.netbeans.org/exceptions/detail.do?id=181893
Comment 9 Martin Balin 2015-09-17 11:25:36 UTC
Report from old NetBeans version. Due to code changes since it was reported likely not reproducible now. Feel free to reopen if happens in 8.0.2 or 8.1.