[ nice-Bugs-1624383 ] A case where nullness inference doesn't quite work
"SourceForge.net" <[email protected]> Sat, 06 Jan 2007 09:02:45 -0800
| Newsgroups | gmane.comp.lang.nice.devel |
|---|---|
| Message-ID | <[email protected]> |
Bugs item #1624383, was opened at 2006-12-29 15:11
Message generated for change (Comment added) made by drmaciver
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=112788&aid=1624383&group_id=12788
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: A case where nullness inference doesn't quite work
Initial Comment:
If you do the following, the nullness inference fails unless you add an assertion:
?Foo bar = null;
bar = myMethod();
doStuff(bar);
Where
public Foo myMethod();
public void doStuff(Foo foo);
The compiler things that foo might be null, and so you can't call doStuff on it.
At least that's what I think is happening. Here's the sample code which this appeared in:
package kakuro;
import java.util.*;
import java.lang.ref.*;
public class CalculationTable<S, T>
{
private HashMap<S, ?SoftReference<T>> values = new HashMap();
private (S -> T) calculate;
public T get(S arg)
{
?SoftReference<T> valueRef = values.get(arg);
?T value;
if (valueRef == null)
{
value = calculate(arg);
}
else
{
value = valueRef.get();
}
if (value == null)
{
value = calculate(arg);
values.put(arg, new SoftReference(value));
}
return value;
}
}
The error occurs with the "new SoftReference(value)".
----------------------------------------------------------------------
Comment By: David R. MacIver (drmaciver)
Date: 2007-01-06 17:02
Message:
Logged In: YES
user_id=1681313
Originator: NO
And here's a minimal example (I thought I'd tested this example before,
but apparently not):
package nullerror;
public void bug()
{
?String value = "";
String otherValue = value;
}
----------------------------------------------------------------------
Comment By: Nobody/Anonymous (nobody)
Date: 2006-12-29 23:17
Message:
Logged In: NO
Here's a greatly pared down piece of test code:
package test;
public class Test1<S, T>
{
private (S -> T) calculate;
public void bug(S arg)
{
?T value = calculate(arg);
T otherValue = id (value);
Test2<T> test2 = new Test2(value : value);
}
}
<T> T id (T arg) = arg;
public class Test2<T>
{
T value;
}
I've not determined exactly how minimal this is, but it should be pretty
near. Note that the nullness inference fails for both the constructor and
the assignment otherValue = id (value). Also, this does appear to have
something to do with the presence of the type parameters.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=112788&aid=1624383&group_id=12788
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV