diff --git a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java index 68d98f303..efeb3670e 100644 --- a/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java +++ b/core/src/main/java/com/ibm/wala/ipa/cha/ClassHierarchy.java @@ -25,6 +25,7 @@ import com.ibm.wala.core.util.ref.CacheReference; import com.ibm.wala.core.util.ref.ReferenceCleanser; import com.ibm.wala.core.util.strings.Atom; +import com.ibm.wala.core.util.strings.StringStuff; import com.ibm.wala.core.util.warnings.Warning; import com.ibm.wala.core.util.warnings.Warnings; import com.ibm.wala.ipa.callgraph.AnalysisScope; @@ -754,13 +755,7 @@ private void helperToJson(Node n, HashMap> hash) { * Removed unnecessary part of Node by turning it into a String (Made for toJson and helperToJson) */ private String nodeToString(Node n) { - String key = n.getJavaClass().toString(); - key = key.replace("", ""); - return key; + return StringStuff.jvmToBinaryName(n.getJavaClass().getName().toString()); } /** diff --git a/core/src/test/java/com/ibm/wala/core/tests/callGraph/ClassConstantTest.java b/core/src/test/java/com/ibm/wala/core/tests/callGraph/ClassConstantTest.java index 4de1fd46f..6c876d161 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/callGraph/ClassConstantTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/callGraph/ClassConstantTest.java @@ -19,6 +19,7 @@ import com.ibm.wala.classLoader.IClass; import com.ibm.wala.core.tests.util.TestConstants; import com.ibm.wala.core.tests.util.WalaTestCase; +import com.ibm.wala.core.util.strings.StringStuff; import com.ibm.wala.ipa.callgraph.AnalysisCacheImpl; import com.ibm.wala.ipa.callgraph.AnalysisOptions; import com.ibm.wala.ipa.callgraph.AnalysisScope; @@ -95,24 +96,21 @@ public void classHierarchyToJson() throws ClassHierarchyException, IOException { ClassHierarchy cha = ClassHierarchyFactory.make(scope); Gson gson = new Gson(); Type type = new TypeToken>>() {}.getType(); - HashMap> list = gson.fromJson(cha.toJson(), type); - assertTrue(list.containsKey(nodeToString(cha.getRootClass().toString()))); + String json = cha.toJson(); + System.err.println(json); + HashMap> list = gson.fromJson(json, type); + assertTrue(list.containsKey(nodeToString(cha.getRootClass()))); Set subclassNames = new HashSet<>(); Iterator children = cha.computeSubClasses(cha.getRootClass().getReference()).iterator(); while (children.hasNext()) { - String temp = nodeToString(children.next().toString()); + String temp = nodeToString(children.next()); subclassNames.add(temp); } - assertTrue(subclassNames.containsAll(list.get(nodeToString(cha.getRootClass().toString())))); + assertTrue(subclassNames.containsAll(list.get(nodeToString(cha.getRootClass())))); } - private String nodeToString(String key) { - key = key.replace("", ""); - return key; + private String nodeToString(IClass klass) { + return StringStuff.jvmToBinaryName(klass.getName().toString()); } }