Warn About Raw Types?

Discussion in 'Java' started by Lawrence D'Oliveiro, Feb 13, 2011.

  1. I was setting up a table of tabs for a tabbed activity in Android. The
    initial part of my table entry definition looks like this:

    class TabParams
    {
    String Name;
    String Title;
    int IconID;
    Class FrameClass;

    Compiled and ran just fine. Then I noticed that “Class†is being used as a
    raw type. So I changed that last line to

    Class<? extends android.app.Activity> FrameClass;

    There doesn’t seem to be any option in javac to warn about this sort of
    thing.
     
    Lawrence D'Oliveiro, Feb 13, 2011
    #1
    1. Advertising

  2. On 14/02/2011 00:21, Lawrence D'Oliveiro allegedly wrote:
    > I was setting up a table of tabs for a tabbed activity in Android. The
    > initial part of my table entry definition looks like this:
    >
    > class TabParams
    > {
    > String Name;
    > String Title;
    > int IconID;
    > Class FrameClass;
    >
    > Compiled and ran just fine. Then I noticed that “Class” is being used as a
    > raw type. So I changed that last line to
    >
    > Class<? extends android.app.Activity> FrameClass;
    >
    > There doesn’t seem to be any option in javac to warn about this sort of
    > thing.


    Epic fail.
     
    Daniele Futtorovic, Feb 13, 2011
    #2
    1. Advertising

  3. Mon, 14 Feb 2011 12:21:34 +1300, /Lawrence D'Oliveiro/:

    > Compiled and ran just fine. Then I noticed that “Class†is being used as a
    > raw type. So I changed that last line to
    >
    > Class<? extends android.app.Activity> FrameClass;
    >
    > There doesn’t seem to be any option in javac to warn about this sort of
    > thing.


    Have you tried:

    % javac
    Usage: javac <options> <source files>
    where possible options include:
    ...
    -X Print a synopsis of nonstandard options

    % javac -X
    -Xlint Enable recommended warnings
    -Xlint:{all,cast,deprecation,divzero,empty,unchecked,fallthrough,path,serial,finally,overrides,-cast,-deprecation,-divzero,-empty,
    -unchecked,-fallthrough,-path,-serial,-finally,-overrides,none}Enable or disable specific warnings
    ...

    --
    Stanimir
     
    Stanimir Stamenkov, Feb 14, 2011
    #3
  4. Lawrence D'Oliveiro

    markspace Guest

    On 2/13/2011 3:21 PM, Lawrence D'Oliveiro wrote:
    > I was setting up a table of tabs for a tabbed activity in Android. The
    > initial part of my table entry definition looks like this:
    >
    > class TabParams
    > {
    > String Name;
    > String Title;
    > int IconID;
    > Class FrameClass;
    >
    > Compiled and ran just fine. Then I noticed that “Class†is being used as a
    > raw type. So I changed that last line to
    >
    > Class<? extends android.app.Activity> FrameClass;
    >
    > There doesn’t seem to be any option in javac to warn about this sort of
    > thing.



    Try this:

    <http://lmgtfy.com/?q=javac+raw+type>


    Third one down on my results list.
     
    markspace, Feb 14, 2011
    #4
  5. In message <ij9roa$oi1$-september.org>, Stanimir Stamenkov wrote:

    > Mon, 14 Feb 2011 12:21:34 +1300, /Lawrence D'Oliveiro/:
    >
    >> Compiled and ran just fine. Then I noticed that “Class†is being used as
    >> a raw type.
    >>
    >> There doesn’t seem to be any option in javac to warn about this sort of
    >> thing.

    >
    > Have you tried:
    >
    > % javac
    > Usage: javac <options> <source files>
    > where possible options include:
    > ...
    > -X Print a synopsis of nonstandard options
    >
    > % javac -X
    > -Xlint Enable recommended warnings
    > -Xlint:{all,cast,deprecation,divzero,empty,unchecked,fallthrough,path,serial,finally,overrides,-cast,-deprecation,-divzero,-empty,
    > -unchecked,-fallthrough,-path,-serial,-finally,-overrides,none}Enable or
    > disable specific warnings


    ldo@theon:java_try> cat test.java
    class test
    {
    public static void main(String[] args)
    {
    Class s = String.class;
    } /*main*/
    }
    ldo@theon:java_try> javac -Xlint test.java
    ldo@theon:java_try> javac -Xlint:deprecation test.java
    ldo@theon:java_try> javac -Xlint:all test.java
    ldo@theon:java_try>

    No warnings.

    Any other suggestions?
     
    Lawrence D'Oliveiro, Feb 14, 2011
    #5
  6. Lawrence D'Oliveiro

    markspace Guest

    On 2/13/2011 5:06 PM, Lawrence D'Oliveiro wrote:

    > ldo@theon:java_try> javac -Xlint test.java
    > ldo@theon:java_try> javac -Xlint:all test.java
    > ldo@theon:java_try>
    >
    > No warnings.
    >
    > Any other suggestions?



    I gotta admit, I thought these would work. There's some documentation
    on the web that seems to indicate it should. But it didn't work for me
    either.
     
    markspace, Feb 14, 2011
    #6
  7. In message <ijac7q$r7p$-september.org>, markspace wrote:

    > On 2/13/2011 5:06 PM, Lawrence D'Oliveiro wrote:
    >
    >> ldo@theon:java_try> javac -Xlint test.java
    >> ldo@theon:java_try> javac -Xlint:all test.java
    >> ldo@theon:java_try>
    >>
    >> No warnings.
    >>
    >> Any other suggestions?

    >
    > I gotta admit, I thought these would work.


    Yeah, all these fucking stupid idiots shooting their mouth off as though
    they really knew something I didn’t...
     
    Lawrence D'Oliveiro, Feb 14, 2011
    #7
  8. On 11-02-14 12:48 AM, markspace wrote:
    > On 2/13/2011 5:06 PM, Lawrence D'Oliveiro wrote:
    >
    >> ldo@theon:java_try> javac -Xlint test.java
    >> ldo@theon:java_try> javac -Xlint:all test.java
    >> ldo@theon:java_try>
    >>
    >> No warnings.
    >>
    >> Any other suggestions?

    >
    >
    > I gotta admit, I thought these would work. There's some documentation on
    > the web that seems to indicate it should. But it didn't work for me either.
    >

    Another useful article:
    http://blogs.sun.com/mcimadamore/entry/diagnosing_raw_types. Somewhat
    dated but I think still largely relevant to this discussion.

    It's perhaps worth noting that if working inside Eclipse that the IDE
    will flag certain raw type usages that are labelled as "harmless" in
    that article (Preferences / Java / Compiler / Errors and Warnings /
    Generic types / Usage of a raw type)

    Pursuant to the article above I think it's actually JDK 7 that
    introduces the -Xlint:rawtypes option. With OpenJDK 6 or Sun jdk 6 you'd
    just have to be somewhat knowledgeable about what you're doing...tall
    order for some characters no doubt.

    AHS
    --
    We must recognize the chief characteristic of the modern era - a
    permanent state of what I call violent peace.
    -- James D. Watkins
     
    Arved Sandstrom, Feb 14, 2011
    #8
  9. Lawrence D'Oliveiro

    Lew Guest

    Arved Sandstrom wrote:
    > Another useful article:
    > http://blogs.sun.com/mcimadamore/entry/diagnosing_raw_types. Somewhat dated
    > but I think still largely relevant to this discussion.
    >
    > It's perhaps worth noting that if working inside Eclipse that the IDE will
    > flag certain raw type usages that are labelled as "harmless" in that article
    > (Preferences / Java / Compiler / Errors and Warnings / Generic types / Usage
    > of a raw type)
    >
    > Pursuant to the article above I think it's actually JDK 7 that introduces the
    > -Xlint:rawtypes option. With OpenJDK 6 or Sun jdk 6 you'd just have to be
    > somewhat knowledgeable about what you're doing...tall order for some
    > characters no doubt.


    God forbid that we should require programmers to be somewhat knowledgeable
    about what they're doing!

    Every time that's suggested in this group you get a lot of squeaky pushback.
    "Oh, you're just a JLS lawyer!" (Is that a bad thing?) "No one should be
    expected to know the entire 'String' interface!" "The ternary operator is too
    confusing!" (And that's just from people who know what "ternary operator"
    means - the usual complaint is, "The question-mark operator is too
    confusing!") "I don't really need to synchronize access, do I?" "What's an
    API doc?"

    --
    Lew
    Honi soit qui mal y pense.
     
    Lew, Feb 14, 2011
    #9
  10. Lawrence D'Oliveiro

    markspace Guest

    On 2/13/2011 10:19 PM, Lawrence D'Oliveiro wrote:

    >
    > Yeah, all these fucking stupid idiots shooting their mouth off as though
    > they really knew something I didn’t...



    To be fair to them, the last three posts you've made in this forum were
    pretty fucking retarded. I guess everyone just assumed that the fucking
    retard boy was just crying fucking wolf again.

    In other news, even a broken clock is right twice a day.
     
    markspace, Feb 14, 2011
    #10
  11. Lawrence D'Oliveiro

    Roedy Green Guest

    On Mon, 14 Feb 2011 12:21:34 +1300, Lawrence D'Oliveiro
    <_zealand> wrote, quoted or indirectly quoted
    someone who said :

    >There doesn’t seem to be any option in javac to warn about this sort of
    >thing.


    Do you have your target set to prior to 1.5? If so, it will not
    complain. Are you using ordinary javac with android or some special
    java in an a IDE?
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    Refactor early. If you procrastinate, you will have
    even more code to adjust based on the faulty design.
    ..
     
    Roedy Green, Feb 15, 2011
    #11
  12. In message <>, Roedy Green wrote:

    > On Mon, 14 Feb 2011 12:21:34 +1300, Lawrence D'Oliveiro
    > <_zealand> wrote, quoted or indirectly quoted
    > someone who said :
    >
    >>There doesn’t seem to be any option in javac to warn about this sort of
    >>thing.

    >
    > Do you have your target set to prior to 1.5?


    From my javac(1) man page:

    The default for -target depends on the value of -source:

    o If -source is not specified, the value of -target is 1.6

    > Are you using ordinary javac with android or some special java in an a
    > IDE?


    The example I posted elsewhere used the javac command with no options
    whatsoever.
     
    Lawrence D'Oliveiro, Feb 15, 2011
    #12
  13. Mon, 14 Feb 2011 14:06:35 +1300, /Lawrence D'Oliveiro/:

    > ldo@theon:java_try> cat test.java
    > class test
    > {
    > public static void main(String[] args)
    > {
    > Class s = String.class;
    > } /*main*/
    > }
    > ldo@theon:java_try> javac -Xlint test.java
    > ldo@theon:java_try> javac -Xlint:deprecation test.java
    > ldo@theon:java_try> javac -Xlint:all test.java
    > ldo@theon:java_try>
    >
    > No warnings.
    >
    > Any other suggestions?


    Trying an example from the "lmgtfy" results [1] given in a reply by
    markspace:

    import java.util.*;
    class test {
    public static void main(String[] args) {
    ArrayList data = new ArrayList();
    data.add("hello");
    data.add("world");

    Iterator<String> it = data.iterator();
    while (it.hasNext()) {
    String s = it.next();
    System.out.println(s);
    }
    }
    }

    I get:

    % javac test.java
    Note: test.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.

    % javac test.java -Xlint
    test.java:5: warning: [unchecked] unchecked call to add(E) as a member of the raw type java.util.ArrayList
    data.add("hello");
    ^
    test.java:6: warning: [unchecked] unchecked call to add(E) as a member of the raw type java.util.ArrayList
    data.add("world");
    ^
    test.java:9: warning: [unchecked] unchecked conversion
    found : java.util.Iterator
    required: java.util.Iterator<java.lang.String>
    Iterator<String> it = data.iterator();
    ^
    3 warnings

    It appears your exact example doesn't make javac emit "unchecked"
    warning, while I can see such warning in my Eclipse IDE. It could
    be related to the "harmless" nature of your example, as indicated
    in the Arved Sandstrom's reply.

    [1] http://www.rgagnon.com/javadetails/java-0521.html

    --
    Stanimir
     
    Stanimir Stamenkov, Feb 15, 2011
    #13
  14. Lawrence D'Oliveiro

    Roedy Green Guest

    On Tue, 15 Feb 2011 14:59:30 +1300, Lawrence D'Oliveiro
    <_zealand> wrote, quoted or indirectly quoted
    someone who said :

    >The example I posted elsewhere used the javac command with no options
    >whatsoever.


    there are lots of programs called Javac floating about the universe.
    Just in case, get it to identify itself with javac -version.
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    Refactor early. If you procrastinate, you will have
    even more code to adjust based on the faulty design.
    ..
     
    Roedy Green, Feb 15, 2011
    #14
  15. In message <>, Roedy Green wrote:

    > On Tue, 15 Feb 2011 14:59:30 +1300, Lawrence D'Oliveiro
    > <_zealand> wrote, quoted or indirectly quoted
    > someone who said :
    >
    >>The example I posted elsewhere used the javac command with no options
    >>whatsoever.

    >
    > there are lots of programs called Javac floating about the universe.
    > Just in case, get it to identify itself with javac -version.


    ldo@theon:~> javac -version
    javac 1.6.0_22

    also:

    ldo@theon:~> dpkg-query -S $(readlink -f $(which javac))
    sun-java6-jdk: /usr/lib/jvm/java-6-sun-1.6.0.22/bin/javac
     
    Lawrence D'Oliveiro, Feb 15, 2011
    #15
  16. In message <ijeu3h$75b$-september.org>, Stanimir Stamenkov
    wrote:

    > It appears your exact example doesn't make javac emit "unchecked"
    > warning, while I can see such warning in my Eclipse IDE. It could
    > be related to the "harmless" nature of your example ...


    If it’s “harmlessâ€, then why is there a warning against it in bold type on
    page 58 of the Java Language Spec?

    <http://groups.google.com/groups?selm=iii9ku$58c$>
     
    Lawrence D'Oliveiro, Feb 15, 2011
    #16
  17. On 14-02-2011 07:15, Lew wrote:
    > Arved Sandstrom wrote:
    >> Another useful article:
    >> http://blogs.sun.com/mcimadamore/entry/diagnosing_raw_types. Somewhat
    >> dated
    >> but I think still largely relevant to this discussion.
    >>
    >> It's perhaps worth noting that if working inside Eclipse that the IDE
    >> will
    >> flag certain raw type usages that are labelled as "harmless" in that
    >> article
    >> (Preferences / Java / Compiler / Errors and Warnings / Generic types /
    >> Usage
    >> of a raw type)
    >>
    >> Pursuant to the article above I think it's actually JDK 7 that
    >> introduces the
    >> -Xlint:rawtypes option. With OpenJDK 6 or Sun jdk 6 you'd just have to be
    >> somewhat knowledgeable about what you're doing...tall order for some
    >> characters no doubt.

    >
    > God forbid that we should require programmers to be somewhat
    > knowledgeable about what they're doing!
    >
    > Every time that's suggested in this group you get a lot of squeaky
    > pushback. "Oh, you're just a JLS lawyer!" (Is that a bad thing?) "No one
    > should be expected to know the entire 'String' interface!" "The ternary
    > operator is too confusing!" (And that's just from people who know what
    > "ternary operator" means - the usual complaint is, "The question-mark
    > operator is too confusing!") "I don't really need to synchronize access,
    > do I?" "What's an API doc?"


    Knowing the more common parts of the Java API and be able to
    look up the rest very quickly is invaluable for a Java developer.

    I am more skeptical about studying the JLS. If the code requires
    JLS studying to figure out what it does or whether it is good, then
    it should be rewritten to something more maintainable.

    And I think it is much better to call it the ?: operator, because
    ternary operator is a general term that just happen to identify
    the operator by the fact that Java currently only have one
    ternary operator.

    Arne
     
    Arne Vajhøj, Feb 16, 2011
    #17
  18. Lawrence D'Oliveiro

    Roedy Green Guest

    On Wed, 16 Feb 2011 12:26:26 +1300, Lawrence D'Oliveiro
    <_zealand> wrote, quoted or indirectly quoted
    someone who said :

    >ldo@theon:~> javac -version
    >javac 1.6.0_22


    that is two versions behind, but not an explanation for your problem.
    see http://mindprod.com/jgloss/jdk.html

    Sounds like time for an SSCCE to nail it down.

    See http://mindprod.com/jgloss/sscce.html
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    Refactor early. If you procrastinate, you will have
    even more code to adjust based on the faulty design.
    ..
     
    Roedy Green, Feb 16, 2011
    #18
  19. Lawrence D'Oliveiro

    Arne Vajhøj Guest

    On 16-02-2011 16:29, Roedy Green wrote:
    > On Wed, 16 Feb 2011 12:26:26 +1300, Lawrence D'Oliveiro
    > <_zealand> wrote, quoted or indirectly quoted
    > someone who said :
    >> ldo@theon:~> javac -version
    >> javac 1.6.0_22

    >
    > that is two versions behind, but not an explanation for your problem.
    > see http://mindprod.com/jgloss/jdk.html
    >
    > Sounds like time for an SSCCE to nail it down.
    >
    > See http://mindprod.com/jgloss/sscce.html


    Sound like time for you actually reading the threads you
    participate in.

    1) He has already posted perfectly compilable code.
    2) Other have verified that the code indeed does not
    come with a warning with SUN Java

    Arne
     
    Arne Vajhøj, Feb 17, 2011
    #19
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jason L. Woodruff

    how to warn?

    Jason L. Woodruff, Sep 9, 2004, in forum: Perl
    Replies:
    1
    Views:
    677
    Andres Monroy-Hernandez
    Sep 10, 2004
  2. Elmo Watson

    Trace.Warn

    Elmo Watson, Oct 29, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    579
    Elmo Watson
    Oct 29, 2003
  3. Tone Curtis
    Replies:
    3
    Views:
    4,536
    Tone Curtis
    Jun 10, 2004
  4. Replies:
    7
    Views:
    25,960
    rohit.net100
    Feb 28, 2011
  5. =?Utf-8?B?Tkg=?=

    Warn user that session expired?

    =?Utf-8?B?Tkg=?=, Jan 6, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    4,196
    Peter Rilling
    Jan 6, 2006
Loading...

Share This Page