matthiasblaesing commented on code in PR #8253: URL: https://github.com/apache/netbeans/pull/8253#discussion_r2017170329
########## java/java.hints/test/unit/src/org/netbeans/modules/java/hints/errors/MagicSurroundWithTryCatchFixTest.java: ########## @@ -47,14 +49,69 @@ public void test104085() throws Exception { "package test; public class Test {public void test() {try {}finally{System.out.println(\"\"); new java.io.FileInputStream(\"\");}}}", 150 - 43, "FixImpl", - "package test; import java.io.FileNotFoundException; import java.util.logging.Level; import java.util.logging.Logger; public class Test {public void test() {try {}finally{try { System.out.println(\"\"); new java.io.FileInputStream(\"\"); } catch (FileNotFoundException ex) { Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex); } }}}"); + "package test; import java.io.FileNotFoundException; import java.util.logging.Level; import java.util.logging.Logger; public class Test {public void test() {try {}finally{try { System.out.println(\"\"); new java.io.FileInputStream(\"\"); } catch (FileNotFoundException ex) { Logger.getLogger(Test.class.getName()).log(Level.SEVERE, \"\", ex); } }}}"); Review Comment: Why this change and the changes below? `null` is perfectly ok to pass to `log` as message. Consider a situation where you just want to log an exception and have nothing more to add. Nothing wrong with null at this point. ########## java/java.hints/src/org/netbeans/modules/java/hints/errors/MagicSurroundWithTryCatchFix.java: ########## Review Comment: I think I see a problem: I chose "Use existing declared logger" in a JDK 9+ project, these were the settings:  With this code:  The existing logger was not reused. ########## java/java.hints/src/org/netbeans/modules/java/hints/MultipleLoggers.java: ########## @@ -67,14 +70,25 @@ public static Iterable<ErrorDescription> checkMultipleLoggers(HintContext ctx) { return null; } + // "sysLoggerTypeElement" may be null if pre Java9; so not a problem. Review Comment: This looks suspicious. Wouldn't be the right approach to try to resolve both `java.util.logging.Logger` (this might not be present, if the `java.logging` module is not present) and `java.lang.System.Logger` (this might not be present in JDK < 9, we still allow editing such code) and then check the fields against both if they could be resolved? ########## java/java.editor/src/org/netbeans/modules/java/editor/codegen/LoggerGenerator.java: ########## @@ -152,15 +164,65 @@ public void run(WorkingCopy copy) throws IOException { } } + public static String getBaseLoggerName() { + // Undocumented feature/property subject to change/removal. Need a UI. + String name = System.getProperty("LOGGER_GENERATOR_BASE_LOGGER_NAME"); + return name == null ? "LOG" : name; + } Review Comment: Please remove without a use case. For normal operation it will not be used as our users won't mess with config (at least the majority), so this is basicly "for you". ########## java/java.hints/src/org/netbeans/modules/java/hints/jackpot/hintsimpl/LoggerStringConcat.java: ########## @@ -172,9 +185,15 @@ private static ErrorDescription compute(HintContext ctx, String methodName) { for (TreePath tp : tps) if (tp.getLeaf().getKind() == Kind.ERRONEOUS) return null; - FixImpl fix = new FixImpl(NbBundle.getMessage(LoggerStringConcat.class, "MSG_LoggerStringConcat_fix"), methodName, TreePathHandle.create(ctx.getPath(), ctx.getInfo()), TreePathHandle.create(message, ctx.getInfo())); + // fixMessageTemplate + FixImpl fix = new FixImpl(Bundle.MSG_LoggerStringConcat_fix(), methodName, TreePathHandle.create(ctx.getPath(), ctx.getInfo()), TreePathHandle.create(message, ctx.getInfo())); + + Fix fixMessageSupplier = null; + if (ctx.getInfo().getSourceVersion().compareTo(SourceVersion.RELEASE_8) >= 0) { + fixMessageSupplier = JavaFixUtilities.rewriteFix(ctx, Bundle.MSG_LoggerStringConcat_fixLambda(), message, "() -> $message"); + } - return ErrorDescriptionFactory.forTree(ctx, message, NbBundle.getMessage(LoggerStringConcat.class, "MSG_LoggerStringConcat"), fix.toEditorFix()); + return ErrorDescriptionFactory.forTree(ctx, message, Bundle.MSG_LoggerStringConcat(), fixMessageSupplier, fix.toEditorFix()); Review Comment: I read this, that you provide two fixes for JDK >= 8: One is a message template and the other is rewrite to supplier. Does `ErrorDescriptionFactory.forTree` accept random fixes to be `null`? I think it would be clearer, if the two cases would be explicitly coded. Return both variants from the if block and the single variant from a, to be added, else block. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org For additional commands, e-mail: notifications-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists