1010import java .net .URI ;
1111import java .nio .file .Files ;
1212import java .nio .file .Path ;
13+ import java .nio .file .Paths ;
14+ import java .util .stream .Collectors ;
1315import java .time .Duration ;
1416import java .util .ArrayList ;
1517import java .util .Arrays ;
18+ import java .util .Collections ;
1619import java .util .Collection ;
1720import java .util .Comparator ;
1821import java .util .LinkedHashMap ;
@@ -68,10 +71,11 @@ void shouldExerciseEveryModelAndCliOptionContract() throws Exception {
6871 }
6972
7073 private List <Class <?>> discoverContractTypes () throws Exception {
71- Path classesRoot = Path . of (OpenClawClient .class .getProtectionDomain ().getCodeSource ().getLocation ().toURI ());
74+ Path classesRoot = Paths . get (OpenClawClient .class .getProtectionDomain ().getCodeSource ().getLocation ().toURI ());
7275 List <Class <?>> result = new ArrayList <>();
73- try (var paths = Files .walk (classesRoot )) {
74- for (Path path : paths .filter (value -> value .toString ().endsWith (".class" )).toList ()) {
76+ java .util .stream .Stream <Path > paths = Files .walk (classesRoot );
77+ try {
78+ for (Path path : paths .filter (value -> value .toString ().endsWith (".class" )).collect (Collectors .toList ())) {
7579 String name = classesRoot .relativize (path ).toString ()
7680 .replace (File .separatorChar , '.' )
7781 .replaceAll ("\\ .class$" , "" );
@@ -80,6 +84,8 @@ private List<Class<?>> discoverContractTypes() throws Exception {
8084 result .add (Class .forName (name ));
8185 }
8286 }
87+ } finally {
88+ paths .close ();
8389 }
8490 result .sort (Comparator .comparing (Class ::getName ));
8591 return result ;
@@ -189,13 +195,13 @@ private Object sampleValue(Class<?> type) {
189195 if (type == byte .class || type == Byte .class ) return (byte ) 1 ;
190196 if (type == char .class || type == Character .class ) return 'x' ;
191197 if (type == Duration .class ) return Duration .ofSeconds (1 );
192- if (type == Path .class ) return Path . of ("target" );
198+ if (type == Path .class ) return Paths . get ("target" );
193199 if (type == File .class ) return new File ("target" );
194200 if (type == URI .class ) return URI .create ("http://localhost" );
195201 if (type == Optional .class ) return Optional .of ("value" );
196- if (type == List .class || type == Collection .class ) return List . of ("value" );
197- if (type == Set .class ) return Set . of ("value" );
198- if (type == Map .class ) return Map . of ("key" , "value" );
202+ if (type == List .class || type == Collection .class ) return Collections . singletonList ("value" );
203+ if (type == Set .class ) return Collections . singleton ("value" );
204+ if (type == Map .class ) return Collections . singletonMap ("key" , "value" );
199205 if (type == Consumer .class ) return (Consumer <Object >) ignored -> { };
200206 if (type == Supplier .class ) return (Supplier <Object >) () -> "value" ;
201207 if (type .isArray ()) {
0 commit comments