You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is not clear if ConnectionFactory can have null Uri property. If ConnectionFactory is created via constructor, Uri property returns null. But, ConnectionFactory does not allow explicit set null Uri.
Reproduction steps
Simple reproduction:
usingRabbitMQ.Client;varc=newConnectionFactory();Console.WriteLine(c.Uri==null);// prints Truec.Uri=null;// throws NullReferenceException
Expected behavior
NullReferenceException is not thrown.
Additional context
This issue was detected by Roslyn analyzer during work on #1596.
The text was updated successfully, but these errors were encountered:
I don't fully understand the design choice to allow users to set and override Uri after ConnectionFactory is created. Maybe the design should be changed to leave only getter and move Uri setting logic into ConnectionFactory constructior? Then we are able to add null check for it.
Here is what I mean:
publicsealedclassConnectionFactory:ConnectionFactoryBase,IConnectionFactory{privateUri?_uri;publicConnectionFactory(Uriuri)// added parameter uri{if(uriisnull)// added null check{thrownewArgumentNullException(nameof(uri));}SetUri(uri);// this is now called in constructorClientProperties=newDictionary<string,object>(DefaultClientProperties);}publicUri?Uri{get{return_uri;}// removed setter}}
This is the cleanest solution, but require breaking change in ConnectionFactory and IConnectionFactory.
@lechu445 please realize that this project's API is very, very old, so issues like this crop up.
Considering that you are the first person to notice or care about this behavior with regard to ConnectionFactory.Uri shows that it is low-priority to address.
I've marked this as a version 8 item so that better design choices can be made. Thanks.
Describe the bug
It is not clear if ConnectionFactory can have null Uri property. If ConnectionFactory is created via constructor, Uri property returns null. But, ConnectionFactory does not allow explicit set null Uri.
Reproduction steps
Simple reproduction:
Expected behavior
NullReferenceException is not thrown.
Additional context
This issue was detected by Roslyn analyzer during work on #1596.
The text was updated successfully, but these errors were encountered: