2525import java .io .ByteArrayInputStream ;
2626import java .io .ByteArrayOutputStream ;
2727import java .io .File ;
28- import java .io .FileReader ;
2928import java .io .IOException ;
3029import java .io .PrintStream ;
3130import java .io .PrintWriter ;
32- import java .io .Reader ;
33- import java .io .UnsupportedEncodingException ;
3431import java .lang .Thread .UncaughtExceptionHandler ;
35- import java .lang .reflect .Method ;
3632import java .net .URL ;
3733import java .net .URLClassLoader ;
38- import java .text .DateFormat ;
34+ import java .nio .charset .StandardCharsets ;
35+ import java .nio .file .Files ;
36+ import java .time .Instant ;
3937import java .util .ArrayList ;
4038import java .util .Collection ;
41- import java .util .Collections ;
42- import java .util .Date ;
4339import java .util .LinkedList ;
4440import java .util .List ;
4541import java .util .Locale ;
4642import java .util .Properties ;
47- import java .util .Set ;
4843import java .util .StringTokenizer ;
4944import java .util .logging .Handler ;
5045import java .util .logging .Level ;
5449import java .util .logging .StreamHandler ;
5550import java .util .regex .Matcher ;
5651import java .util .regex .Pattern ;
57- import java .util .stream .Collectors ;
5852import org .netbeans .NbExit ;
5953import org .netbeans .core .startup .logging .NbLogging ;
6054import org .openide .filesystems .FileUtil ;
@@ -181,12 +175,8 @@ private static void initialize(boolean verbose) {
181175 try (PrintStream ps = new PrintStream (os )) {
182176 logging .printSystemInfo (ps );
183177 }
184- try {
185- Logger logger = Logger .getLogger (TopLogging .class .getName ()); // NOI18N
186- logger .log (Level .INFO , os .toString ("utf-8" ));
187- } catch (UnsupportedEncodingException ex ) {
188- assert false ;
189- }
178+ Logger logger = Logger .getLogger (TopLogging .class .getName ()); // NOI18N
179+ logger .log (Level .INFO , os .toString (StandardCharsets .UTF_8 ));
190180 }
191181 if (!Boolean .getBoolean ("netbeans.logger.noSystem" )) {
192182 if (!PrintStreamLogger .isLogger (System .err )) {
@@ -202,11 +192,9 @@ private static void initialize(boolean verbose) {
202192
203193
204194 private void printSystemInfo (PrintStream ps ) {
205- DateFormat df = DateFormat .getDateTimeInstance (DateFormat .FULL , DateFormat .FULL , Locale .US );
206- Date date = new Date ();
207195
208196 ps .println ("-------------------------------------------------------------------------------" ); // NOI18N
209- ps .println (">Log Session: " + df . format ( date )); // NOI18N
197+ ps .println (">Log Session: " + Instant . now ( )); // NOI18N
210198 ps .println (">System Info: " ); // NOI18N
211199
212200 List <File > clusters = new ArrayList <>();
@@ -228,20 +216,17 @@ private void printSystemInfo(PrintStream ps) {
228216 for (File cluster : clusters ) { // also print Hg ID if available; more precise
229217 File buildInfo = new File (cluster , "build_info" ); // NOI18N
230218 if (buildInfo .isFile ()) {
231- try {
232- try (Reader r = new FileReader (buildInfo )) {
233- BufferedReader b = new BufferedReader (r );
234- Pattern p = Pattern .compile ("Hg ID: ([0-9a-f]{12})" ); // NOI18N
235- for (;;) {
236- String line = b .readLine ();
237- if (line == null ) {
238- break ;
239- }
240- Matcher m = p .matcher (line );
241- if (m .matches ()) {
242- ps .print (" (#" + m .group (1 ) + ")" ); // NOI18N
243- break ;
244- }
219+ Pattern p = Pattern .compile ("Hg ID: ([0-9a-f]{12})" ); // NOI18N
220+ try (BufferedReader br = Files .newBufferedReader (buildInfo .toPath ())) {
221+ for (;;) {
222+ String line = br .readLine ();
223+ if (line == null ) {
224+ break ;
225+ }
226+ Matcher m = p .matcher (line );
227+ if (m .matches ()) {
228+ ps .print (" (#" + m .group (1 ) + ")" ); // NOI18N
229+ break ;
245230 }
246231 }
247232 } catch (IOException x ) {
@@ -276,7 +261,8 @@ private void printSystemInfo(PrintStream ps) {
276261 ps .println (" Cache Directory = " + Places .getCacheDirectory ()); // NOI18N
277262 ps .print ( " Installation = " ); // NOI18N
278263 for (File cluster : clusters ) {
279- ps .print (cluster + "\n " ); // NOI18N
264+ ps .println (cluster );
265+ ps .print (" " );// NOI18N
280266 }
281267 ps .println (CLIOptions .getHomeDir ()); // platform cluster is separate
282268 ps .println (" Boot & Ext. Classpath = " + createBootClassPath ()); // NOI18N
@@ -286,9 +272,9 @@ private void printSystemInfo(PrintStream ps) {
286272 cp = System .getProperty ("java.class.path" , "unknown" ); // NOI18N
287273 } else {
288274 StringBuilder sb = new StringBuilder ("loaded by " ); // NOI18N
289- if (l instanceof URLClassLoader ) {
275+ if (l instanceof URLClassLoader urlCL ) {
290276 sb .append ("URLClassLoader" ); // NOI18N
291- for (URL u : (( URLClassLoader ) l ) .getURLs ()) {
277+ for (URL u : urlCL .getURLs ()) {
292278 sb .append (' ' ).append (u );
293279 }
294280 } else {
@@ -315,29 +301,10 @@ private static String createBootClassPath() {
315301 }
316302
317303 private List <String > createJavaBootModuleList () {
318- // TODO JDK 11 equivalent
319- // return ModuleLayer.boot().modules().stream()
320- // .map(Module::getName)
321- // .sorted()
322- // .collect(Collectors.toList());
323- try {
324- Class <?> ml_class = Class .forName ("java.lang.ModuleLayer" );
325- Method mod_getName = Class .forName ("java.lang.Module" ).getMethod ("getName" );
326- @ SuppressWarnings ("unchecked" )
327- Set <?> mods = (Set <?>)ml_class .getDeclaredMethod ("modules" ).invoke (
328- ml_class .getDeclaredMethod ("boot" ).invoke (null )
329- );
330- return mods .stream ().map (mod -> {
331- try {
332- return (String ) mod_getName .invoke (mod );
333- } catch (ReflectiveOperationException ex ) {
334- return "unknown" ; // outer try would fail first
335- }
336- })
337- .sorted ().collect (Collectors .toList ());
338- } catch (ReflectiveOperationException ex ) {
339- return Collections .emptyList ();
340- }
304+ return ModuleLayer .boot ().modules ().stream ()
305+ .map (Module ::getName )
306+ .sorted ()
307+ .toList ();
341308 }
342309
343310 /** Scans path list for something that can be added to classpath.
@@ -501,9 +468,6 @@ public void uncaughtException(Thread t, Throwable e) {
501468 if (e .getClass ().getName ().endsWith (".ExitSecurityException" )) { // NOI18N
502469 return ;
503470 }
504- if (e instanceof ThreadDeath ) {
505- return ;
506- }
507471 g .log (Level .SEVERE , null , e );
508472 }
509473 } // end of AWTHandler
0 commit comments