36
36
import java .nio .file .Path ;
37
37
import java .nio .file .Paths ;
38
38
import java .util .ArrayList ;
39
+ import java .util .HashSet ;
39
40
import java .util .List ;
40
41
import java .util .Map ;
42
+ import java .util .Set ;
41
43
import java .util .concurrent .ExecutionException ;
42
44
import java .util .regex .Pattern ;
43
45
@@ -142,7 +144,8 @@ public final String findModuleThatExports(String className, String toModuleName)
142
144
modulePackageCache .put (modInfo .getModuleName () + "/" + packageName , modInf .getModuleName ());
143
145
return modInf .getModuleName ();
144
146
} else {
145
- String tModuleName = checkTransitiveChain (modInf , packageName , toModuleName );
147
+ Set <String > hasCheckedModule = new HashSet <String >();
148
+ String tModuleName = checkTransitiveChain (modInf , packageName , toModuleName , hasCheckedModule );
146
149
if (tModuleName != null ) {
147
150
modulePackageCache .put (modInfo .getModuleName () + "/" + packageName , tModuleName );
148
151
return tModuleName ;
@@ -162,13 +165,18 @@ public final String findModuleThatExports(String className, String toModuleName)
162
165
* @param toModuleName defined moduleName
163
166
*
164
167
*/
165
- private String checkTransitiveChain (SootModuleInfo modInfo , String packageName , String toModuleName ) {
168
+ private String checkTransitiveChain (SootModuleInfo modInfo , String packageName , String toModuleName , Set < String > hasCheckedModule ) {
166
169
for (Map .Entry <SootModuleInfo , Integer > entry : modInfo .retrieveRequiredModules ().entrySet ()) {
167
170
if ((entry .getValue () & Modifier .REQUIRES_TRANSITIVE ) != 0 ) {// check if module is exported via "requires public"
171
+ if (hasCheckedModule .contains (entry .getKey ().getModuleName ())) {
172
+ continue ;
173
+ } else {
174
+ hasCheckedModule .add (entry .getKey ().getModuleName ());
175
+ }
168
176
if (entry .getKey ().exportsPackage (packageName , toModuleName )) {
169
177
return entry .getKey ().getModuleName ();
170
178
} else {
171
- return checkTransitiveChain (entry .getKey (), packageName , toModuleName );
179
+ return checkTransitiveChain (entry .getKey (), packageName , toModuleName , hasCheckedModule );
172
180
}
173
181
}
174
182
}
0 commit comments