Created
August 31, 2011 21:57
-
-
Save jcalvert/1184842 to your computer and use it in GitHub Desktop.
Find the NullPointerException!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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