Skip to content

Avro 3603 dotnet reflect refactoring 1#1823

Closed
KhrystynaPopadyuk wants to merge 11 commits intoapache:masterfrom
KhrystynaPopadyuk:avro-3603-dotnet-reflect-refactoring-1
Closed

Avro 3603 dotnet reflect refactoring 1#1823
KhrystynaPopadyuk wants to merge 11 commits intoapache:masterfrom
KhrystynaPopadyuk:avro-3603-dotnet-reflect-refactoring-1

Conversation

@KhrystynaPopadyuk
Copy link
Contributor

Jira

My PR addresses the following Avro Jira issues and references them in the PR title.

Tests

TBD

Commits

My commits all reference Jira issues in their subject lines.

Documentation

TBU

@github-actions github-actions bot added the C# label Aug 12, 2022
case Schema.Type.Error:
case Schema.Type.Record:
return _classCache.GetClass(sc as RecordSchema).GetClassType() == obj.GetType();
return _reflectCache.GetClass(sc.Fullname).GetClassType() == obj.GetType();

Check warning

Code scanning / CodeQL

Dereferenced variable may be null

Variable [obj](1) may be null here as suggested by [this](2) null check. Variable [obj](1) may be null here as suggested by [this](3) null check.
return _reflectCache.GetClass(sc.Fullname).GetClassType() == obj.GetType();
case Schema.Type.Enumeration:
return EnumCache.GetEnumeration(sc as EnumSchema) == obj.GetType();
return _reflectCache.GetEnum(sc.Fullname) == obj.GetType();

Check warning

Code scanning / CodeQL

Dereferenced variable may be null

Variable [obj](1) may be null here as suggested by [this](2) null check. Variable [obj](1) may be null here as suggested by [this](3) null check.
}

return c;
return (DotnetClass)GetClass(schema.Fullname);

Check warning

Code scanning / CodeQL

Call to obsolete method

Call to obsolete method [GetClass](1).
throw new AvroException($"Type {dotnetClass.Name} is not a class");
}

_refletCache.AddClass(schema.Fullname, _dotnetclassFactory.CreateDotnetClass(schema, dotnetClass));

Check warning

Code scanning / CodeQL

Dereferenced variable may be null

Variable [schema](1) may be null here as suggested by [this](2) null check.
private static ConcurrentBag<IAvroFieldConverter> _defaultConverters = new ConcurrentBag<IAvroFieldConverter>();

private ConcurrentDictionary<string, DotnetClass> _nameClassMap = new ConcurrentDictionary<string, DotnetClass>();
private ConcurrentDictionary<string, IDotnetClass> _nameClassMap = new ConcurrentDictionary<string, IDotnetClass>();

Check notice

Code scanning / CodeQL

Missed 'readonly' opportunity

Field '_nameClassMap' can be 'readonly'.
{
private ConcurrentDictionary<string, DotnetProperty> _propertyMap = new ConcurrentDictionary<string, DotnetProperty>();

private Dictionary<string, IDotnetProperty> _propertyMap;

Check notice

Code scanning / CodeQL

Missed 'readonly' opportunity

Field '_propertyMap' can be 'readonly'.
Comment on lines +90 to +97
foreach (var attr in p.GetCustomAttributes(true))
{
var avroAttr = attr as AvroFieldAttribute;
if (avroAttr != null && avroAttr.FieldName != null && avroAttr.FieldName == field.Name)
{
return p;
}
}

Check notice

Code scanning / CodeQL

Missed opportunity to use OfType

This foreach loop immediately uses 'as' to coerce its iteration variable to another type [here](1) - consider using '.OfType(...)' instead.
Comment on lines +115 to +121
foreach (var c in _convertors)
{
if (c.GetAvroType() == avroType && c.GetPropertyType() == property.PropertyType)
{
return c;
}
}

Check notice

Code scanning / CodeQL

Missed opportunity to use Where

This foreach loop implicitly filters its target sequence [here](1) - consider filtering the sequence explicitly using '.Where(...)'.
Comment on lines +98 to +111
foreach (var f in rs.Fields)
{
/*
//.StackOverflowException
var t = c.GetPropertyType(f);
LoadClassCache(t, f.Schema);
*/
if (!previousFields.ContainsKey(f.Name))
{
previousFields.Add(f.Name, f.Schema);
var t = c.GetPropertyType(f);
LoadClassCache(t, f.Schema);
}
}

Check notice

Code scanning / CodeQL

Missed opportunity to use Where

This foreach loop implicitly filters its target sequence [here](1) - consider filtering the sequence explicitly using '.Where(...)'.
Comment on lines +174 to +180
foreach (var o in us.Schemas)
{
if (o.Tag == Schema.Type.Record && _refletCache.GetClass(o.Fullname) == null)
{
throw new AvroException($"Class for union record type {o.Fullname} is not registered. Create a ClassCache object and call LoadClassCache");
}
}

Check notice

Code scanning / CodeQL

Missed opportunity to use Where

This foreach loop implicitly filters its target sequence [here](1) - consider filtering the sequence explicitly using '.Where(...)'.
/// <returns></returns>
public IAvroFieldConverter GetConverter(Schema schema, PropertyInfo property)
{
return _converterService.GetConverter(schema, property) ?? GetDefaultConverter(schema.Tag, property.PropertyType);

Check warning

Code scanning / CodeQL

Call to obsolete method

Call to obsolete method [GetDefaultConverter](1).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant