JayOfemi opened a new issue, #936:
URL: https://github.com/apache/lucenenet/issues/936

   ### Is there an existing issue for this?
   
   - [X] I have searched the existing issues
   
   ### Describe the bug
   
   I am simply trying to create a StandardQueryParser. I get the below 
exception only on Android and iOS. This makes sense as `System.Console.In` is 
not supported on these platforms, but I have no need for it in the context of 
our application. So, I think a way to ignore this would be very useful to 
prevent our app from crashing on these platforms.
   
   It seems the issue is the way these properties are setup in 
`Lucene.Net.Util.SystemConsole`.
   
   ```
   public static TextWriter Out { get; set; } = Console.Out;
   public static TextWriter Error { get; set; } = Console.Error;
   public static TextReader In { get; set; } = Console.In;
   ```
   
   My application would work fine to simply return null here when Console.In is 
not supported.
   
   I can't seem to find anything online about this regarding Lucene, so I think 
it is just specific to Lucene.NET and .NET MAUI. In any case, I believe it can 
possible be addressed simply by doing the above.
   
   From what I can tell, `SystemConsole` is only used in 
`StandardSyntaxParserTokenManager` to create the private `debugStream` 
property, which is then never used in this class. I believe this whole thing is 
the same when using the default QueryParser as well.
   
   ### Expected Behavior
   
   Perhaps instead of defaulting to `Console.In`, the property can be set in a 
way that if a non-supported or any other exceptions that can be ignored is 
caught, this property returns null or a bogus TextWriter by default.
   
   ### Steps To Reproduce
   
   * In a .NET MAUI sample app, create a 
`Lucene.Net.QueryParsers.Flexible.Standard.StandardQueryParser` using the 
constructor.
       * Specifically we created our MAUI app using the default template in 
Rider.
   * Run the app.
   on Windows and macOS, this will run fine. On Android and iOS, the app will 
crash with a `System.PlatformNotSupportedException` when it attempts to 
construct the `StandardQueryParser`.
   
   ### Exceptions (if any)
   
   ```
   Exception: System.TypeInitializationException: The type initializer for 
'Lucene.Net.Util.SystemConsole' threw an exception.
    ---> System.PlatformNotSupportedException: Operation is not supported on 
this platform.
      at System.ConsolePal.GetOrCreateReader()
      at System.Console.<get_In>g__EnsureInitialized|14_0()
      at System.Console.get_In()
   2024-04-29 15:55:32.051142-0700  at Lucene.Net.Util.SystemConsole..cctor()
      --- End of inner exception stack trace ---
      at 
Lucene.Net.QueryParsers.Flexible.Standard.Parser.StandardSyntaxParserTokenManager..ctor(ICharStream
 stream)
   2024-04-29 15:55:32.051200-0700  at 
Lucene.Net.QueryParsers.Flexible.Standard.Parser.StandardSyntaxParser..ctor(ICharStream
 stream)
      at 
Lucene.Net.QueryParsers.Flexible.Standard.Parser.StandardSyntaxParser..ctor()
      at Lucene.Net.QueryParsers.Flexible.Standard.StandardQueryParser..ctor()
   2024-04-29 15:55:32.051439-0700 at 
Lucene.Net.QueryParsers.Flexible.Standard.StandardQueryParser..ctor(Analyzer 
analyzer)
   ```
   
   ### Lucene.NET Version
   
   4.8
   
   ### .NET Version
   
   8.0.203
   
   ### Operating System
   
   Windows 11
   
   ### Anything else?
   
   _No response_


-- 
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: dev-unsubscr...@lucenenet.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to