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 225676 - Java Hints don't consider source code level
Summary: Java Hints don't consider source code level
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Project (show other bugs)
Version: 7.3
Hardware: Macintosh Mac OS X
: P3 normal (vote)
Assignee: Tomas Zezula
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-02-03 20:34 UTC by twolf2919
Modified: 2013-02-04 19:54 UTC (History)
1 user (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
IDE log (46.47 KB, text/plain)
2013-02-03 20:34 UTC, twolf2919
Details

Note You need to log in before you can comment on or make changes to this bug.
Description twolf2919 2013-02-03 20:34:36 UTC
I have a project with Java 6 source code (i.e. Project->Sources is set to "JDK 6") but, for various reasons, am using a Java 7 Platform for the project.  In order for the Java 7 javac to accept my Java 6 source code, I specify "-source 1.6 -target 1.6 -bootclasspath ..." as compiler options in Project->Build->Compiling).  Everything builds just fine, but NB's "Hints" flags two of my files as having errors: a class that implements java.sql.ResultSet and one that implements java.sql.Driver.  Both of the interfaces have new methods in Java 7 that my classes don't implement - but my classes are Java 6, so they don't need to!  It appears that the Java Hints don't consider that the sources are set to "JDK 6" - a version lower than the platform being used for the project?

The main reason I consider this a bug rather than an enhancement is that there's an inconsistency between the build results and what Java Hints claims.

This is not a NB 7.3-specific bug - the same is the case for NB 7.2.1.

Product Version = NetBeans IDE 7.3 RC1 (Build 201301240957)
Operating System = Mac OS X version 10.8.2 running on x86_64
Java; VM; Vendor = 1.6.0_37
Runtime = Java HotSpot(TM) 64-Bit Server VM 20.12-b01-434
Comment 1 twolf2919 2013-02-03 20:34:40 UTC
Created attachment 130968 [details]
IDE log
Comment 2 Jan Lahoda 2013-02-04 09:34:53 UTC
(In reply to comment #0)
> I have a project with Java 6 source code (i.e. Project->Sources is set to "JDK
> 6") but, for various reasons, am using a Java 7 Platform for the project.  In
> order for the Java 7 javac to accept my Java 6 source code, I specify "-source
> 1.6 -target 1.6 -bootclasspath ..." as compiler options in

Note the "-bootclasspath" parameter. So the settings in the build and for the internal parser are apparently not the same, leading to different end results. Depending on project type (which leads me to a question: what project type do you use?), sending the proper bootclasspath may (in which case this is a misconfigured project) or may not (in which case this is a request for enhancement for the project type to support it) be supported, but generally I don't see that the Java parsing (and much less the code that shows the errors, described herein as "Java Hints") could do much about that.
Comment 3 twolf2919 2013-02-04 17:15:09 UTC
Jan,
My project type is Java SE "Java Project with existing source".  I understand that the "-target" and "-source" and "-bootclasspath" lead to a possible difference between what the build does and what Java Hints do.  My question, I guess, is: why are NB "Hints"  showing Java 7 issues in the source code when the source code is clearly identified as being Java 6?  That question is independent of what is being done to the build via compiler options.
Comment 4 Jan Lahoda 2013-02-04 17:32:19 UTC
(In reply to comment #3)
> Jan,
> My project type is Java SE "Java Project with existing source".  I understand
> that the "-target" and "-source" and "-bootclasspath" lead to a possible
> difference between what the build does and what Java Hints do.  My question, I
> guess, is: why are NB "Hints"  showing Java 7 issues in the source code when
> the source code is clearly identified as being Java 6?  That question is
> independent of what is being done to the build via compiler options.

Please try to remove the "-bootclasspath" parameter, and I am pretty sure you will see the same outcome as in the IDE. "-source" does not exactly mean "Java SE 6" it is more like "Java *language* version 6", which is to a great extent independent on the version of standard libraries (set via "-bootclasspath").

Overall, the reason why we can't reasonably infer the bootclasspath from -source is that "@since" is not part of the classfile, and it is therefore basically impossible to filter the 1.7-only stuff from 1.7 standard libraries.
Comment 5 twolf2919 2013-02-04 19:13:01 UTC
Hi Jan,
If I remove "-bootclasspath", I get the warning:
    warning: [options] bootstrap class path not set in conjunction with -source 1.6
and the build shows the same errors that the HInts show.  But that's not a solution for me.  I'm trying to build my Java 6 compliant source code using a Java 7 compiler/platform (because I want the GUI part of the project to RUN in a Java 7 JRE in my IDE  - the parts of the project that depend on Java 6/libraries are never executed from inside the IDE - they're server-side code).  It looks like NB isn't granular enough - one can only specify the platform under "Libraries" - and that is then used during build and at runtime.  That is why I resorted to compiler options.

Thanks for clarifying what "-source 1.6" means - I see your point.  But I don't think most people are (or would be) aware of this nuance - especially since the property in ""Project->Properties->Sources->"Source/Binary Format" gives you the options "JDK 1.4', "JDK 6", "JDK 7", etc.  - not "Java 6", "Java 7", etc.  A JDK consists of both the language AND the tools/libraries, no?  Anyway, I have no strong feelings about this bug.  Maybe, at a minimum, the options' text should be changed?  If you could point me to any open bug that might exist to enhance NB to specify separate build & runtime environments, I could vote for it.
Comment 6 twolf2919 2013-02-04 19:54:59 UTC
Just as a related side note: one of the reasons (but not the only one) that I went the route of specifying a Java 7 platform even though my code is Java 6 is the fact that starting in NB 7.3rc1, when I used the Java 6 platform, I got "out of memory" conditions on the build (see below) -  the same project using the same Java 6 platform built just fine in NB 7.2.1.  In neither of the NB versions do I specify anything w.r.t. heap size in netbeans.conf file.

The system is out of resources.
Consult the following stack trace for details.
java.lang.OutOfMemoryError: Java heap space
	at com.sun.tools.javac.tree.TreeMaker.Select(TreeMaker.java:383)
	at com.sun.tools.javac.parser.Parser.term3(Parser.java:1026)
	at com.sun.tools.javac.parser.Parser.term2(Parser.java:683)
	at com.sun.tools.javac.parser.Parser.term1(Parser.java:654)
	at com.sun.tools.javac.parser.Parser.term(Parser.java:610)
	at com.sun.tools.javac.parser.Parser.term(Parser.java:592)
	at com.sun.tools.javac.parser.Parser.blockStatements(Parser.java:1542)
	at com.sun.tools.javac.parser.Parser.block(Parser.java:1459)
	at com.sun.tools.javac.parser.Parser.block(Parser.java:1473)
	at com.sun.tools.javac.parser.Parser.methodDeclaratorRest(Parser.java:2529)
	at com.sun.tools.javac.parser.Parser.classOrInterfaceBodyDeclaration(Parser.java:2478)
	at com.sun.tools.javac.parser.Parser.classOrInterfaceBody(Parser.java:2405)
	at com.sun.tools.javac.parser.Parser.classDeclaration(Parser.java:2250)
	at com.sun.tools.javac.parser.Parser.classOrInterfaceOrEnumDeclaration(Parser.java:2188)
	at com.sun.tools.javac.parser.Parser.typeDeclaration(Parser.java:2177)
	at com.sun.tools.javac.parser.Parser.compilationUnit(Parser.java:2123)
	at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:509)
	at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:550)
	at com.sun.tools.javac.main.JavaCompiler.parseFiles(JavaCompiler.java:804)
	at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:727)
	at com.sun.tools.javac.main.Main.compile(Main.java:353)
	at com.sun.tools.javac.main.Main.compile(Main.java:279)
	at com.sun.tools.javac.main.Main.compile(Main.java:270)
	at com.sun.tools.javac.Main.compile(Main.java:69)
	at com.sun.tools.javac.Main.main(Main.java:54)
/Users/twolf/NetBeansProjects/trunk/nbproject/build-impl.xml:952: The following error occurred while executing this line:
/Users/twolf/NetBeansProjects/trunk/nbproject/build-impl.xml:299: Compile failed; see the compiler error output for details.