Skip to content

Instantly share code, notes, and snippets.

@jcalvert
Created August 31, 2011 21:57
Show Gist options
  • Save jcalvert/1184842 to your computer and use it in GitHub Desktop.
Save jcalvert/1184842 to your computer and use it in GitHub Desktop.
Find the NullPointerException!
public abstract class AbstractLoader {
protected LoadJob loadJob;
public AbstractLoader(LoadJob loadJob)
{
this.loadJob = loadJob;
int foo = 0; //Doing stuff
String bar = "foobar";
this.load1();
}
protected abstract void load1();
}
public class LoaderImpl extends AbstractLoader {
private Map<String, String> syncMap =
Collections.synchronizedMap(new HashMap<String,String>());
public LoaderImpl(LoadJob loadJob) {
super(loadJob);
}
@Override
protected void load1() {
loadJob.initializeMap(syncMap);
System.out.println("SYNC?? "+Boolean.toString(syncMap == null));
(new Thread(loadJob)).run();
}
}
public class LoadJob implements Runnable {
Map<String,String> map;
public void initializeMap(Map<String,String> map)
{
this.map = map;
}
@Override
public void run() {
synchronized(map)
{
map.put("foo", "bar");
}
}
}
public class LoaderTest {
public static void main(String[] args) {
new LoaderImpl(new LoadJob());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment