paulirwin commented on issue #932: URL: https://github.com/apache/lucenenet/issues/932#issuecomment-2587577461
I reviewed this yesterday, and in addition to the translation errors in the original issue, there is highly inconsistent translation of `printStackTrace`. I'm going to do a sweep of all usages and have it use a common extension method so that it is translated correctly. As @NightOwl888 noted: > In .NET, Exception.StackTrace doesn't contain the exception type, so a lot of the tests use Exception.ToString() instead. In Java, `printStackTrace` includes the exception type and message before printing the stack trace, so this is effectively the same as printing `e.ToString()`. There were several cases where this was omitted, or translated into two `Console.WriteLine` calls, which just begs to have future translation issues (or set bad precedence). To solve this, I'm moving the TestFramework's `printStackTrace` extension method overloads into Support's `ExceptionExtensions`, fixing the capitalization of them to match .NET conventions, and having them print an output that is equivalent to Java's. This will let us translate `e.printStackTrace()` to `e.PrintStackTrace()` (or `e.printStackTrace(System.out)` to `e.PrintStackTrace(Console.Out)`) which will feel like a very natural and foolproof translation of the code. These methods are set to AggressiveInlining so they should not harm performance. (Most of the usage is in test or console code, anyways.) Additionally, I'm moving the StackTraceHelper type into Support as noted in the original ticket, with a new method `PrintCurrentStackTrace` that does what the original issue needs. It uses `new StackTrace(skipFrames: 1)` with `NoInlining` so that the `PrintCurrentStackTrace` method is omitted from the printed stack trace, while `NoInlining` ensures that we don't miss any frames by having this inlined and then skipping the calling method frame. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
