IDE plugin to help null handling

A

Albert

Hi, let's say i'm in my favorite java IDE, and i want to use a method or
a field of some object. Wouldn't be cool to have some sort of popup to
show me that the return value of the method or the field is tested
aginst null never/sometimes/always ? I'm saying this idea because i
don't have time to do a plugin for eclipse or netbeans, but maybe
someone else does...

What do you think of the idea ?
 
L

Lew

Albert said:
Hi, let's say i'm [sic] in my favorite java [sic] IDE, and i [sic] want to use a method or
a field of some object. Wouldn't be cool to have some sort of popup to
show me that the return value of the method or the field is tested
aginst null never/sometimes/always ? I'm saying this idea because i [sic]
don't have time to do a plugin for eclipse [sic] or netbeans [sic], but maybe
someone else does...

What do you think of the idea ?

I think it's already been done, at least partly. Eclipse-based IDEs show
warnings for variables that might be null at a point of dereferencing, but I'm
not sure about method returns, or if NetBeans has the same feature. I also
don't know what you mean by the "return value" of a field or what sort of test
you want the IDE to check for. Have you used FindBugs? I think that covers
whatever you might have in mind.
 
N

neuneudr

Hi, let's say i'm in my favorite java IDE, and i want to use a method or
a field of some object. Wouldn't be cool to have some sort of popup to
show me that the return value of the method or the field is tested
aginst null never/sometimes/always ? I'm saying this idea because i
don't have time to do a plugin for eclipse or netbeans, but maybe
someone else does...

What do you think of the idea ?

I cannot code in Java without:

- The IntelliJ IDEA Java (and now much more than just Java) IDE
- The @NotNull annotations fully supported in IntelliJ IDEA

My code is littered with @NotNull and should the possibility
of null being assigned to an @NotNull annotated reference
(including reference returned by methods), then IntelliJ IDEA
tells it to you immediately.

In the very rare case where null is acceptable, then you shoul
use the @Nullable annotation to make your intent clear.

People who have not used it do not realize how helpful it is.

The IntelliJ IDEA itself, which is arguably one of the very
best client-side Java application ever developped, is using
these @NotNull/@Nullable annotations extensively.
 
N

neuneudr

I cannot code in Java without:

- The IntelliJ IDEA Java (and now much more than just Java) IDE
- The @NotNull annotations fully supported in IntelliJ IDEA

My code is littered with @NotNull and should the possibility
of null being assigned to an @NotNull annotated reference
(including reference returned by methods), then IntelliJ IDEA
tells it to you immediately.

In the very rare case where null is acceptable, then you shoul
use the @Nullable annotation to make your intent clear.

People who have not used it do not realize how helpful it is.

The IntelliJ IDEA itself, which is arguably one of the very
best client-side Java application ever developped, is using
these @NotNull/@Nullable annotations extensively.

For example:

import org.jetbrains.annotations.NotNull;

public interface ObservableSubject {

void registerObserver( @NotNull MeshObserver observer);

void unregisterObserver( @NotNull MeshObserver observer);

void notifyObservers();

}

Not using this annotation is coding with grandpa's last
century Java IDE and programming practices ;) [trolling]
 
R

Roedy Green

Hi, let's say i'm in my favorite java IDE, and i want to use a method or
a field of some object. Wouldn't be cool to have some sort of popup to
show me that the return value of the method or the field is tested
aginst null never/sometimes/always ? I'm saying this idea because i
don't have time to do a plugin for eclipse or netbeans, but maybe
someone else does...

Each IDE has its own scheme for writing plugins. I wrote one of the
authors of an IntelliJ plugin to ask how he learned to write them. He
wrote back saying they were poorly documented and somewhat rinky dink,
at least for IntelliJ.

The trick I think is to find somebody else's code that does something
remotely similar to what you want to do, and fiddle with it until you
understand it.

It is hard to create a good tool the first time out. You need to use
it for a while to figure out what you really wanted.
--
Roedy Green Canadian Mind Products
http://mindprod.com

"Perfect reusable components are not obtained at the first shot."
~ Bertrand Meyer (born: 1950 age: 59) 1989, creator of design by contract and the Eiffel language.
 
R

Roedy Green

Hi, let's say i'm in my favorite java IDE, and i want to use a method or
a field of some object. Wouldn't be cool to have some sort of popup to
show me that the return value of the method or the field is tested
aginst null never/sometimes/always ? I'm saying this idea because i
don't have time to do a plugin for eclipse or netbeans, but maybe
someone else does...

Some possibilities:

1. look into other charting packages. Something else might be faster.
see http://mindprod.com/jgloss/graph.html

2. Consider painting the new chart to an offscreen buffer, and only
when it is ready blast it to the screen on top of what was previously
there.

3. You suggested that data was travelling over some slow serial port.
Perhaps it could be compressed, or predigested to be more compact.
Perhaps you can use a faster port e.g. USB 2, or Ethernet.

4. try the program on another machine with a relatively expensive
video card to rule out a bottleneck with the video driver or hardware.

Your first task is to figure out where the bottleneck is. You need to
figure out how to run your program to eliminate the possible
bottlenecks by simply not doing the work and seeing if the thing
greatly speeds up.
--
Roedy Green Canadian Mind Products
http://mindprod.com

"Perfect reusable components are not obtained at the first shot."
~ Bertrand Meyer (born: 1950 age: 59) 1989, creator of design by contract and the Eiffel language.
 
D

Dave Searles

Roedy said:
Some possibilities:

1. look into other charting packages. Something else might be faster.
see http://mindprod.com/jgloss/graph.html

2. Consider painting the new chart to an offscreen buffer, and only
when it is ready blast it to the screen on top of what was previously
there.

3. You suggested that data was travelling over some slow serial port.
Perhaps it could be compressed, or predigested to be more compact.
Perhaps you can use a faster port e.g. USB 2, or Ethernet.

4. try the program on another machine with a relatively expensive
video card to rule out a bottleneck with the video driver or hardware.

Your first task is to figure out where the bottleneck is. You need to
figure out how to run your program to eliminate the possible
bottlenecks by simply not doing the work and seeing if the thing
greatly speeds up.

How is any of that relevant?
 
J

John B. Matthews

Dave Searles said:
Roedy Green wrote: [...]
Some possibilities:

1. look into other charting packages. Something else might be faster.
see http://mindprod.com/jgloss/graph.html

2. Consider painting the new chart to an offscreen buffer, and only
when it is ready blast it to the screen on top of what was previously
there.

3. You suggested that data was travelling over some slow serial port.
Perhaps it could be compressed, or predigested to be more compact.
Perhaps you can use a faster port e.g. USB 2, or Ethernet.

4. try the program on another machine with a relatively expensive
video card to rule out a bottleneck with the video driver or hardware.

Your first task is to figure out where the bottleneck is. You need to
figure out how to run your program to eliminate the possible
bottlenecks by simply not doing the work and seeing if the thing
greatly speeds up.

How is any of that relevant?

Roedy's thoughtful response was no doubt intended for this thread:

<http://groups.google.com/group/comp.lang.java.programmer/browse_frm/
thread/3d16165f9b86d9d0>
 
L

Lew

My code is littered with @NotNull and should the possibility

"Littered", eh?
of null being assigned to an @NotNull annotated reference
(including reference returned by methods), then IntelliJ IDEA
tells it to you immediately.

All IDEs that I've used, and javac itself, recognize an assertion for this
purpose, though of course the behavior is different from an annotation.
In the very rare case where null is acceptable, then you shoul
use the @Nullable annotation to make your intent clear.

People who have not used it do not realize how helpful it is.

The IntelliJ IDEA itself, which is arguably one of the very
best client-side Java application ever developped, is using
these @NotNull/@Nullable annotations extensively.

I turn a jaundiced eye to an IDE-specific approach when a portable one works
well enough.

Using, for example, Eclipse or derived IDEs, a snippet like

if ( foo == null )
{
doSomethingThatCouldThrowException();
}
foo.execute();

will cause a complaint at the foo method call that foo might be null. Suppose
the 'doSomething...()' method is known to throw an exception - you could
precede 'foo.execute()' with an 'assert foo != null;' to satisfy the IDE.

More generally I suggest that the null branch explicitly throw whatever it
needs to rather than depend on a method to do so, and optionally assert the
invariant after the block:

if ( foo == null )
{
throw new IllegalArgumentException( "null foo" );
}
assert foo != null;
foo.execute();
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top