github-code-scanning[bot] commented on code in PR #1940:
URL: https://github.com/apache/avro/pull/1940#discussion_r1011296986
##########
lang/csharp/src/apache/main/Reflect/ClassCache.cs:
##########
@@ -19,17 +19,19 @@
using System;
using System.Collections;
using System.Collections.Concurrent;
+using Avro.Reflect.Interfaces.Models;
+using Avro.Reflect.Interfaces.Services;
namespace Avro.Reflect
{
/// <summary>
/// Class holds a cache of C# classes and their properties. The key for
the cache is the schema full name.
/// </summary>
- public class ClassCache
+ public class ClassCache : ICacheService, IArrayService
{
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>();
Review Comment:
## Missed 'readonly' opportunity
Field '_nameClassMap' can be 'readonly'.
[Show more
details](https://github.com/apache/avro/security/code-scanning/2881)
##########
lang/csharp/src/apache/main/Reflect/ReflectDefaultWriter.cs:
##########
@@ -188,7 +211,7 @@
return obj is string;
case Schema.Type.Error:
case Schema.Type.Record:
- return _classCache.GetClass(sc as
RecordSchema).GetClassType() == obj.GetType();
+ return _cacheService.GetClass(sc as
RecordSchema).GetClassType() == obj.GetType();
Review Comment:
## Dereferenced variable may be null
Variable [obj](1) may be null at this access as suggested by [this](2) null
check.
Variable [obj](1) may be null at this access as suggested by [this](3) null
check.
[Show more
details](https://github.com/apache/avro/security/code-scanning/2926)
##########
lang/csharp/src/apache/main/Reflect/DotnetClass.cs:
##########
@@ -20,15 +20,16 @@
using System.Reflection;
using System.Collections.Concurrent;
using Avro;
+using Avro.Reflect.Interfaces.Models;
namespace Avro.Reflect
{
/// <summary>
/// Collection of DotNetProperty objects to repre
/// </summary>
- public class DotnetClass
+ public class DotnetClass : IDotnetClass
{
- private ConcurrentDictionary<string, DotnetProperty> _propertyMap =
new ConcurrentDictionary<string, DotnetProperty>();
+ private ConcurrentDictionary<string, IDotnetProperty> _propertyMap =
new ConcurrentDictionary<string, IDotnetProperty>();
Review Comment:
## Missed 'readonly' opportunity
Field '_propertyMap' can be 'readonly'.
[Show more
details](https://github.com/apache/avro/security/code-scanning/2927)
##########
lang/csharp/src/apache/main/Reflect/ReflectDefaultWriter.cs:
##########
@@ -28,12 +29,14 @@
/// </summary>
public class ReflectDefaultWriter : SpecificDefaultWriter
{
- private ClassCache _classCache = new ClassCache();
-
/// <summary>
/// Class cache
/// </summary>
- public ClassCache ClassCache { get => _classCache; }
+ [Obsolete]
+ public ClassCache ClassCache { get => _cacheService as ClassCache; }
+
+ private ICacheService _cacheService;
Review Comment:
## Missed 'readonly' opportunity
Field '_cacheService' can be 'readonly'.
[Show more
details](https://github.com/apache/avro/security/code-scanning/2930)
##########
lang/csharp/src/apache/main/Reflect/ReflectDefaultReader.cs:
##########
@@ -37,12 +38,14 @@
/// </summary>
public Type MapType { get => _mapType; set => _mapType = value; }
- private ClassCache _classCache = new ClassCache();
-
/// <summary>
/// Class cache
/// </summary>
- public ClassCache ClassCache { get => _classCache; }
+ [Obsolete]
+ public ClassCache ClassCache { get => _cacheService as ClassCache; }
+
+ private ICacheService _cacheService;
Review Comment:
## Missed 'readonly' opportunity
Field '_cacheService' can be 'readonly'.
[Show more
details](https://github.com/apache/avro/security/code-scanning/2928)
##########
lang/csharp/src/apache/main/Reflect/ReflectDefaultWriter.cs:
##########
@@ -28,12 +29,14 @@
/// </summary>
public class ReflectDefaultWriter : SpecificDefaultWriter
{
- private ClassCache _classCache = new ClassCache();
-
/// <summary>
/// Class cache
/// </summary>
- public ClassCache ClassCache { get => _classCache; }
+ [Obsolete]
+ public ClassCache ClassCache { get => _cacheService as ClassCache; }
+
+ private ICacheService _cacheService;
+ private IArrayService _arrayService;
Review Comment:
## Missed 'readonly' opportunity
Field '_arrayService' can be 'readonly'.
[Show more
details](https://github.com/apache/avro/security/code-scanning/2931)
##########
lang/csharp/src/apache/main/Reflect/ReflectDefaultReader.cs:
##########
@@ -37,12 +38,14 @@
/// </summary>
public Type MapType { get => _mapType; set => _mapType = value; }
- private ClassCache _classCache = new ClassCache();
-
/// <summary>
/// Class cache
/// </summary>
- public ClassCache ClassCache { get => _classCache; }
+ [Obsolete]
+ public ClassCache ClassCache { get => _cacheService as ClassCache; }
+
+ private ICacheService _cacheService;
+ private IArrayService _arrayService;
Review Comment:
## Missed 'readonly' opportunity
Field '_arrayService' can be 'readonly'.
[Show more
details](https://github.com/apache/avro/security/code-scanning/2929)
--
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]