avoid crashes in LoadFileTargetSelector

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@4500 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
msridhar1 2012-02-17 20:24:08 +00:00
parent 1eb7236267
commit e60be259ae
3 changed files with 7 additions and 4 deletions

View File

@ -141,12 +141,11 @@ public class JSCallGraphUtil extends com.ibm.wala.cast.ipa.callgraph.CAstCallGra
* @param cl
* @param fileName
* @param url
* @param file
* @return The set of class names that where defined in the CHA as a result
* loading process.
* @throws IOException
*/
public static Set<String> loadAdditionalFile(IClassHierarchy cha, JavaScriptLoader cl, String fileName, URL url, String file)
public static Set<String> loadAdditionalFile(IClassHierarchy cha, JavaScriptLoader cl, String fileName, URL url)
throws IOException {
try {
SourceURLModule M = new SourceURLModule(url);

View File

@ -430,7 +430,7 @@ public class JavaScriptConstructTargetSelector implements MethodTargetSelector {
FO.write(fun.toString());
FO.close();
Set<String> fnNames = JSCallGraphUtil.loadAdditionalFile(cha, cl, fileName, f.toURI().toURL(), f.getAbsolutePath());
Set<String> fnNames = JSCallGraphUtil.loadAdditionalFile(cha, cl, fileName, f.toURI().toURL());
IClass fcls = null;
for(String nm : fnNames) {
if (nm.endsWith("_fromctor")) {

View File

@ -1,6 +1,7 @@
package com.ibm.wala.cast.js.ipa.callgraph;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashSet;
@ -60,7 +61,10 @@ public class LoadFileTargetSelector implements MethodTargetSelector {
JavaScriptLoader cl = (JavaScriptLoader) builder.getClassHierarchy().getLoader(JavaScriptTypes.jsLoader);
URL url = new URL(builder.getBaseURL(), str);
if(!loadedFiles.contains(url)) {
JSCallGraphUtil.loadAdditionalFile(builder.getClassHierarchy() , cl, str, url, url.getFile());
// try to open the input stream for the URL. if it fails, we'll get an IOException and fall through to default case
InputStream inputStream = url.openConnection().getInputStream();
inputStream.close();
JSCallGraphUtil.loadAdditionalFile(builder.getClassHierarchy() , cl, str, url);
loadedFiles.add(url);
IClass script = builder.getClassHierarchy().lookupClass(TypeReference.findOrCreate(cl.getReference(), "L" + url.getFile()));
return script.getMethod(JavaScriptMethods.fnSelector);