Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #32950

Re: A hypothetical compiler extension

From Arne Vajhøj <arne@vajhoej.dk>
Newsgroups comp.lang.java.programmer
Subject Re: A hypothetical compiler extension
Date 2015-10-27 22:21 -0400
Organization Aioe.org NNTP Server
Message-ID <n0pbf2$ld5$1@speranza.aioe.org> (permalink)
References <extension-20151027221547@ram.dialup.fu-berlin.de>

Show all headers | View raw


On 10/27/2015 5:24 PM, Stefan Ram wrote:
>    The following is hypothetical AFAIK, but wouldn't it be nice?
>
>    One calls
>
> javac -Xlint:null
>
>    and then
>
> void m( final java.lang.Object o )
> { java.lang.System.out.println
>    ( o.toString() ); }
>
>    gives
>
>    ( o.toString() ); }
>      ^
> Warning: o might be null.
>
>    . One rewrites to
>
> void m( final java.lang.Object o )
> { if( o != null )
>    java.lang.System.out.println
>    ( o.toString() ); }
>
>    and the warning disappears.
>
>    Javac alread has path-value-analysis as it already can
>    detect when a path of execution of a method (think of
>    nested ifs) accesses a variable that has not been
>    defined yet in this path.

I don't think it would be appropriate for the compiler
to complain about something that very well may not be
a problem due to something being done in the calling code.

Defensive coding is good, but it should be a developer
choice not something that the compiler get involved in.

The local variable not having gotten a value is a slightly
different case as it will either happen or the code has
been structured badly for the task.

Arne



Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Re: A hypothetical compiler extension Arne Vajhøj <arne@vajhoej.dk> - 2015-10-27 22:21 -0400
  Re: A hypothetical compiler extension Martin Gregorie <martin@address-in-sig.invalid> - 2015-10-28 11:50 +0000
    Re: A hypothetical compiler extension Arne Vajhøj <arne@vajhoej.dk> - 2015-10-28 20:09 -0400
      Re: A hypothetical compiler extension Martin Gregorie <martin@address-in-sig.invalid> - 2015-10-29 12:24 +0000
        Re: A hypothetical compiler extension Jeff Higgins <jeff@invalid.invalid> - 2015-10-29 18:36 -0400

csiph-web