paulirwin opened a new issue, #932:
URL: https://github.com/apache/lucenenet/issues/932
`new Exception().StackTrace` is an incorrect translation from Java. We
should find all calls to `Exception.StackTrace` as well as the `StackTrace`
class and convert them correctly. From ChatGPT:
> In Java, the code `new Exception().getStackTrace()` creates a new instance
of the `Exception` class, and then calls the `getStackTrace()` method on that
instance to obtain an array of `StackTraceElement` objects. Each element in the
array represents a stack trace element, providing information about the call
stack at the point where the exception was created.
>
> Here's an example of how it might be used:
>
> ```java
> StackTraceElement[] trace = new Exception().getStackTrace();
>
> for (StackTraceElement element : trace) {
> System.out.println(element.getClassName() + " - " +
element.getMethodName() + " - " + element.getLineNumber());
> }
> ```
>
> This code prints out the class name, method name, and line number for each
element in the stack trace.
>
> In C#, the equivalent code would use the `StackTrace` class from the
`System.Diagnostics` namespace. Here's an example:
>
> ```c#
> using System;
> using System.Diagnostics;
>
> class Program
> {
> static void Main()
> {
> StackTrace trace = new StackTrace();
> StackFrame[] frames = trace.GetFrames();
>
> foreach (StackFrame frame in frames)
> {
> Console.WriteLine($"{frame.GetMethod().DeclaringType} -
{frame.GetMethod().Name} - {frame.GetFileLineNumber()}");
> }
> }
> }
> ```
>
> This C# code creates a new `StackTrace` instance and then uses the
`GetFrames()` method to obtain an array of `StackFrame` objects. Similar to the
Java example, it prints out the declaring type, method name, and line number
for each frame in the stack trace.
We have a class called `StackTraceHelper` that we could add the support to
convert it to a string. There are also several calls to `.printStackTace()`
that should be reviewed. In .NET, `Exception.StackTrace` doesn't contain the
exception type, so a lot of the tests use `Exception.ToString()` instead. But
we would be better off with a centralized way of dealing with stack traces (in
Support) - `StackTraceHelper` only applies to the test code, but there is code
in production that is also not correctly translated. Of course, since it is
something we own, moving it to Support is an option.
In short, we want to review all of the code that was using
`.getStackTrace()` or `.printStackTrace()` in Lucene.
_Originally posted by @NightOwl888 in
https://github.com/apache/lucenenet/pull/926#discussion_r1521058105_
--
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]