| Summary: | [reconciler] Type safety: The expression of type ... needs unchecked conversion to conform to ... | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Nathan Reynolds <numeralnathan> | ||||||||||
| Component: | Core | Assignee: | Stephan Herrmann <stephan.herrmann> | ||||||||||
| Status: | CLOSED WORKSFORME | QA Contact: | |||||||||||
| Severity: | minor | ||||||||||||
| Priority: | P3 | CC: | aussiemcgr, jarthana, stephan.herrmann | ||||||||||
| Version: | 4.3 | ||||||||||||
| Target Milestone: | 4.15 RC1 | ||||||||||||
| Hardware: | PC | ||||||||||||
| OS: | Windows 7 | ||||||||||||
| Whiteboard: | stalebug | ||||||||||||
| Attachments: |
|
||||||||||||
I can't reproduce in Kepler.
Neither in full compilation nor incremental.
I tried compliance 1.6 and 1.7 to no avail.
If you have non-default compiler settings please attach .settings/org.eclipse.jdt.core.prefs
I can, however, force the warning by changing the definition of ServeMe to
public class ServeMe<T> { ...
but in that case the warnings is actually expected.
Created attachment 233344 [details]
Compiler settings
I am running Kepler 20130614-0229. I am using compliance level 1.7. I have attached my compiler settings. (In reply to comment #2) > Created attachment 233344 [details] > Compiler settings I still can't reproduce using these settings. Obviously those settings that refer to files on your hard disk don't have any effect for me (org.eclipse.jdt.core.classpathVariable.* and org.eclipse.jdt.core.userLibrary.*), but I don't see how those would influence the compiler for this issue. Are you sure you see the problem with the exact sources which you pasted in comment 0? (In reply to comment #3) > I am running Kepler 20130614-0229. I am using compliance level 1.7. I have > attached my compiler settings. Hm, I can't find the version string 20130614-0229 anywhere in Kepler release. Where exactly did you find that? Could you please post the exact file name of the org.eclipse.jdt.core plugin inside your <eclipse>/plugins folder? TIA > I still can't reproduce using these settings. Obviously those settings that > refer to files on your hard disk don't have any effect for me > (org.eclipse.jdt.core.classpathVariable.* and > org.eclipse.jdt.core.userLibrary.*), > but I don't see how those would influence the compiler for this issue. > > Are you sure you see the problem with the exact sources which you pasted in > comment 0? I should admit that I ran into the problem and searched the Internet for a solution. I found someone had the same problem with the code that I then put in the bug. I put their code in the bug since it was very similar to mine and theirs was already distilled to the minimal amount of code required. I finally took the code in this bug and put it in my IDE. I got a bunch of warnings including the warning that triggered this bug. I cleaned up the code to get rid of the extra warnings. For example, "new ArrayList<Field>()" should be "new ArrayList<>()". The local variable fields is not used in doSomething() so I put it in a System.out.println(). doSomething() should be a static since it doesn't use any member variables. And so forth. I am now left with only the original warning that triggered this bug. So, I have reproduced the problem with their code. > > (In reply to comment #3) > > I am running Kepler 20130614-0229. I am using compliance level 1.7. I have > > attached my compiler settings. > > Hm, I can't find the version string 20130614-0229 anywhere in Kepler release. > Where exactly did you find that? When I go to Help | About the "About Eclipse" dialog box pops up. The dialog box says... Eclipse Java EE IDE for Web Developers. Version: Kepler Release Build id: 20130614-0229 (c) Copyright Eclipse.... I download this the day the Kepler release shipped plus some "Check for Updates". > Could you please post the exact file name of the org.eclipse.jdt.core plugin inside your <eclipse>/plugins folder? I did a dir *org.eclipse.jdt.core* /s /b and got the following results. C:\Eclipse\plugins\org.eclipse.jdt.core.manipulation_1.5.0.v20130605-1748.jar C:\Eclipse\plugins\org.eclipse.jdt.core_3.9.0.v20130604-1421.jar C:\Eclipse\plugins\edu.umd.cs.findbugs.plugin.eclipse_2.0.2.20121210\src\eclipsePlugin-2.0.2.20121210\.settings\org.eclipse.jdt.core.prefs C:\Eclipse\plugins\findbugs\src\eclipsePlugin-2.0.2.20121210\.settings\org.eclipse.jdt.core.prefs (In reply to comment #5) Your versions look correct. Sorry I didn't know the qualifier used by the packages. Which leaves us with the problem that I simply cannot reproduce the bug, not even using the exact same Eclipse package. Yes, I saw all the other warnings you mention but not the one in question. The only difference I see at this point concerns those options mentioned in comment 4. Could you please try removing all org.eclipse.jdt.core.classpathVariable.* and org.eclipse.jdt.core.userLibrary.* from your preferences file. Does that change anything? OTOH, seeing the original thread on java-forums.org open with the same problems of not being able to reproduce I lean towards closing as WORKSFORME. Feel free to provide more evidence that this is indeed reproduceable on more than just this particular machine/workspace/setup. Another strange thing about this warning is that the file's icon in Project Explorer isn't marked with a warning. However... 1) The code is underlined in yellow 2) There is a warning marker in the gutter 3) It displays the warning in a tool tip when I mouse over the code I checked the Markers | Java Problems and the warning doesn't appear in that list. If I add an unused local variable to the Java source, then I get #1, #2 and #3 above. I also get a warning icon in Project Explorer and a line in Markers | Java Problems. (In reply to comment #6) > (In reply to comment #5) > > The only difference I see at this point concerns those options mentioned in > comment 4. > Could you please try removing all org.eclipse.jdt.core.classpathVariable.* > and > org.eclipse.jdt.core.userLibrary.* from your preferences file. Does that > change > anything? This doesn't change anything. I even did Project | Clean to force a rebuild of the workspace. (In reply to comment #7) > Another strange thing about this warning is that the file's icon in Project > Explorer isn't marked with a warning. However... > > 1) The code is underlined in yellow > 2) There is a warning marker in the gutter > 3) It displays the warning in a tool tip when I mouse over the code > > I checked the Markers | Java Problems and the warning doesn't appear in that > list. OK, that's some hint: the compiler works in several different modes: When doing full compilation as to generate .class files it will also create markers in the Problems view and package explorer. When working as a "reconciler" to update the editor with unsaved changes it marks problems only in the editor and gutter. Now we "only" need to figure out, why in your environment the reconciler behaves differently from the compiler and differently from compiler and reconciler in my environment... I'm having no luck reproducing no matter what I try. To rule out any tiny differences between projects, please export your project incl. all configuration files (.classpath, .project). Finally a list of any plug-ins which you installed on top of the Java EE package *might* give a hint. (In reply to comment #10) > To rule out any tiny differences between projects, please export your > project incl. all configuration files (.classpath, .project). > > Finally a list of any plug-ins which you installed on top of the Java EE > package > *might* give a hint. I originally added this files to an existing "big" project to reproduce the warning. However, at this request, I created a new Java project and added these two files. The plan was to package up this "small" project to make things easier. Unfortunately, the warning doesn't show up! So I don't blame you for having a difficult time in reproducing this warning. So, I diffed the two projects. I looked in .classpath first. I noticed that the big project had a reference to another project. So, I added that reference. This didn't reproduce the warning. I looked in .project. Nothing different there except the name of the project. The .settings folder for the big project doesn't have any files. However, the .settings folder for the small project has a file named "org.eclipse.jdt.core.prefs" (to be attached). I closed Eclipse and copied the file from the small project to the big project. I then started Eclipse. The warning disappeared from the big project!! I then closed Eclipsed, deleted the file and started Eclipse. The warning is back. I have successfully narrowed down how to "fix" the problem. On the small project, I opened up the properties and unchecked "Enable project specific settings". After hitting okay, the warning now appears in the small project and "org.eclipse.jdt.core.prefs" is deleted from the project's .settings folder. So, this leads me to believe that some setting in the "Configure Workspace Settings..." is causing the problem. When I open that window, I see that the settings appear to be identical... at least in the GUI. What about the settings from "Use compliance from execution environment 'JavaSE-1.7' on the 'Java Build Path'? Created attachment 233398 [details]
File from .settings folder in small project
(In reply to comment #10) > To rule out any tiny differences between projects, please export your > project incl. all configuration files (.classpath, .project). > > Finally a list of any plug-ins which you installed on top of the Java EE > package *might* give a hint. How do I export my project? How do I create a list of plug-ins? Do I simply attach a "dir" list of C:\Eclipse\plugins? (In reply to comment #13) > How do I export my project? Just sharing the contents of the project folder should suffice. > How do I create a list of plug-ins? Do I simply attach a "dir" list of > C:\Eclipse\plugins? Or if you can recall the plug-ins you installed as add-ons (if any) after you installed eclipse and specifying the version of eclipse you use would be good enough. Created attachment 233530 [details]
Entire project reproducing the issue.
Created attachment 233531 [details]
Directory Listing of C:\Eclipse\Plugins
I am not sure if this is relevant... when I am creating a new Java Project I see a message at the bottom of the "Create a Java Project" dialog box. It says... The default compiler compliance level for the current workspace is 1.4. The new project will use a project specific compiler compliance level of 1.7. (In reply to comment #17) > I am not sure if this is relevant... when I am creating a new Java Project I > see a message at the bottom of the "Create a Java Project" dialog box. It > says... > > The default compiler compliance level for the current workspace is 1.4. The > new project will use a project specific compiler compliance level of 1.7. This isn't applicable. If I configure the workspace settings to "Use default compliance settings", then the message disappears. This has no impact on the warning which produced this bug. I've had the same issue, and I've found reliable reproduction steps for my issues. This does not seem like how the OP had their stuff set up, but this should be reproducible and it is the same issue.
For me, I had 2 projects:
**Project #1 was a Maven project, with the java version set to 1.7 in the POM. The project in the Eclipse Package Explorer was reading as using JRE System Library: JavaSE-1.7. This project had the method which returned the List (in the OP's example, this project would contain the ServeMe class).
**Project #2 was not a Maven project, but had Project #1 as a dependent. This project had its JRE System Library set to the default workspace JRE, which is jdk1.7.0_45. This project contains a class which calls the method from Project #1 (in the OP's example, this project would contain the MakeMeHappy class).
I believe the primary cause for me was an inconsistent JRE use (as far as Eclipse is concerned). If I changed one of them so they were using the same JRE (as represented in Eclipse's package explorer), the warning went away.
Also, I would like to add that attempting to suppress the warning, with @SuppressWarnings("unchecked"), per Eclipse's suggestion, gets rid of the warning on the List, but leads to a warning on the suppression: "Unnecessary @SuppressWarnings("unchecked")". If you then remove that line, also per the Eclipse suggestion, the previous warning on the List reappears.
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug. If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie. Too bad I left the discussion before looking at the attachments in comment 15 and comment 16. Unfortunately: - the project zip doesn't contain file .settings/org.eclipse.jdt.core.prefs - refers to a missing project - adding an empty project "Utilities" does not let me reproduce the problem => WORKSFORME |
I have two classes: MakeMeHappy and ServeMe. ServeMe has a method that returns a List<Field>. But in MakeMeHappy, there is a warning reported. It reads: Type safety: The expression of type List needs unchecked conversion to conform to List<Field> package barnacles; import java.util.ArrayList; import java.util.List; import java.lang.reflect.Field; public class ServeMe { private final List<Field> fields = new ArrayList<Field>(); public List<Field> getFields() { return this.fields; } } package barnacles; import java.util.List; import java.lang.reflect.Field; public class MakeMeHappy { public void doSomething() { ServeMe server = new ServeMe(); List<Field> fields = server.getFields(); // Warning here } }