Incorrect compiler error

80 views
Skip to first unread message

Tim Moloney

unread,
Apr 8, 2008, 12:41:28 PM4/8/08
to Q for Eclipse users list
I'm getting error messages complaining about generics when it doesn't
make sense. For example, I'm getting this error message

The type List is not generic; it cannot be parameterized with
arguments <Sdw>

from this line of code

List<Sdw> sdws = sdwList.getSdw();

I'm using Java SE 6 and verified that Eclipse is using the correct
version. In fact, I removed all other versions of Java and GCJ from
my Linux system. What's odd is that other correct uses of generics
won't get an error message. What's more odd is that lines without any
semblance to generics will get the same type of error message.

For example a file header comment of an enum class is flagged with

The type Comparable is not generic; it cannot be parameterized with
arguments <E>

and this line

sdwRecord.putDouble(sdw.getPrf());

generates

The type Comparable is not generic; it cannot be parameterized with
arguments <ByteBuffer>

I don't see this with non-Maven projects but with the inconsistency,
I'm not sure if it's Q4E or Eclipse. Has anyone else seen this
before?

Tim

Abel Muiño Vizcaino

unread,
Apr 8, 2008, 2:10:06 PM4/8/08
to q4e-...@googlegroups.com
I don't think it's q4e, since compilation is done by eclipse (so there should be no interference).

However, it is possible to select which goals are executed on the incremental builds. Please check your project properties > Maven JDT and verify that all the goals touching the java classes (compile, etc...) are not selected.

If you see nothing strange and can reproduce the issue in a test project, please open an issue and attach the test case.


Abel Muiño Vizcaino

unread,
Apr 8, 2008, 4:42:06 PM4/8/08
to q4e-...@googlegroups.com
Hi Tim,

I think you're seeing this in a project which depends on "org.osgi.foundation" (a transitive dependency of org.apache.felix:org.osgi.compendium). Am I right?

This dependency includes classes from the java.* packages, which look like a 1.4 (or earlier) version. So there's no support for generics.
The workaround is to either move the JRE container up in the classpath or to exclude the dependency.

I'm supposing that you're using an scenario similar to the test case attached at Issue 328 (jaxb requires generics, org.osgi.foundation does not have them).
El 08/04/2008, a las 18:41, Tim Moloney escribió:

Tim Moloney

unread,
Apr 9, 2008, 8:44:03 AM4/9/08
to Q for Eclipse users list
You are correct that these errors are from a bundle that depends on
the compendium jar.

I will try both adjusting the classpath and excluding the foundation
jar as a dependency. I am away from my computer today, but I will do
this tomorrow and get back with you on the results.

Thanks for the excellent detective work.

Tim


On Apr 8, 4:42 pm, Abel Muiño Vizcaino <amu...@gmail.com> wrote:
> Hi Tim,
>
> I think you're seeing this in a project which depends on
> "org.osgi.foundation" (a transitive dependency of
> org.apache.felix:org.osgi.compendium). Am I right?
>
> This dependency includes classes from the java.* packages, which look
> like a 1.4 (or earlier) version. So there's no support for generics.
> The workaround is to either move the JRE container up in the
> classpath or to exclude the dependency.
>
> I'm supposing that you're using an scenario similar to the test case
> attached at Issue 328 (jaxb requires generics, org.osgi.foundation
> does not have them).
> --
> Abel Muiño Vizcaino -http://ramblingabout.wordpress.com

Tim Moloney

unread,
Apr 10, 2008, 11:32:51 AM4/10/08
to Q for Eclipse users list
Both suggestions work (I chose to exclude the foundation jar from the
dependencies).


Now I am getting Eclipse warnings for all of the generic classes. For example

private static Map marshallers;

generates

Map is a raw type. References to generic type Map<K,V> should be
parameterized.

I'm using these correctly and I want the generic class, not the
implementation, so I don't understand the warnings.

I know that this isn't a Q4E problem but I was hoping that while I had
your attention...


Thanks,
Tim

--
Tim Moloney
ManTech Real-time Systems Laboratory
2015 Cattlemen Road \ /
Sarasota, FL 34232 .________\(O)/________.
(941) 377-6775 x208 ' ' O(.)O ' '

Josh Suereth

unread,
Apr 10, 2008, 2:54:22 PM4/10/08
to q4e-...@googlegroups.com
Add @SupressWarnings tag for "generic" warnings on the method.  Eclipse should give you the option to do this (ctrl-1).  The other option is to turn off generic warnings by the compiler.

Robert Dale

unread,
Apr 10, 2008, 3:03:50 PM4/10/08
to q4e-...@googlegroups.com
On Thu, Apr 10, 2008 at 11:32 AM, Tim Moloney <tim.m...@gmail.com> wrote:
>
> Both suggestions work (I chose to exclude the foundation jar from the
> dependencies).
>
>
> Now I am getting Eclipse warnings for all of the generic classes. For example
>
> private static Map marshallers;

This is not generic.

> generates
>
> Map is a raw type. References to generic type Map<K,V> should be
> parameterized.
>
> I'm using these correctly and I want the generic class, not the
> implementation, so I don't understand the warnings.

A catch-all generic would be, Map<?,?>. This will get rid of your warnings.

You really should have it typed if possible, Map<String, IFoo>

--
Robert Dale

Tim Moloney

unread,
Apr 10, 2008, 3:25:17 PM4/10/08
to q4e-...@googlegroups.com
You are correct. Thanks for pointing that out and sorry for the noise.

Tim

--

Tim Moloney

unread,
Apr 10, 2008, 3:26:27 PM4/10/08
to q4e-...@googlegroups.com
Thanks, I have used this in the few cases that I couldn't fix using
Robert's suggestion.

Tim

Reply all
Reply to author
Forward
0 new messages