Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING: Id field of Location changed from int(32bit) to BigInteger(unlimited) #2463

Merged
merged 20 commits into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ReleaseHistory.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* BUGFIX: Fix `Merge` command produces empty SARIF file in Linux when providing file name only without path. [#2408](https://github.com/microsoft/sarif-sdk/pull/2408)
* BUGFIX: Fix `NullReferenceException` when filing work item with a SARIF file which has no filable results. [#2412](https://github.com/microsoft/sarif-sdk/pull/2412)
* BUGFIX: Fix missing `endLine` and `endColumn` properties and remove vulnerable packages for ESLint SARIF formatter. [#2458](https://github.com/microsoft/sarif-sdk/pull/2458)
* BREAKING: `Id` field of `Location` changed from `int`(32bit) to `BigInteger`(unlimited) [#2463](https://github.com/microsoft/sarif-sdk/pull/2463)
Copy link
Member

@michaelcfanning michaelcfanning Mar 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

field

use 'property' not 'field' as a term. Add something about the exception message you see on deserializing a id value larger than 2^31 #Closed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated


## **v2.4.12** [Sdk](https://www.nuget.org/packages/Sarif.Sdk/2.4.12) | [Driver](https://www.nuget.org/packages/Sarif.Driver/2.4.12) | [Converters](https://www.nuget.org/packages/Sarif.Converters/2.4.12) | [Multitool](https://www.nuget.org/packages/Sarif.Multitool/2.4.12) | [Multitool Library](https://www.nuget.org/packages/Sarif.Multitool.Library/2.4.12)

Expand Down
14 changes: 10 additions & 4 deletions src/Sarif/Autogenerated/Location.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Numerics;
using System.Runtime.Serialization;
using Microsoft.CodeAnalysis.Sarif.Readers;

using Newtonsoft.Json;

namespace Microsoft.CodeAnalysis.Sarif
Expand Down Expand Up @@ -40,7 +41,12 @@ public virtual SarifNodeKind SarifNodeKind
[DataMember(Name = "id", IsRequired = false, EmitDefaultValue = false)]
[DefaultValue(-1)]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
public virtual int Id { get; set; }
public virtual BigInteger Id { get; set; }

public bool ShouldSerializeId()
{
return Id != -1;
Copy link
Member

@michaelcfanning michaelcfanning Mar 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return Id != -1

return Id >-1; #Closed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a unit test for this.

}
Copy link
Collaborator Author

@shaopeng-gh shaopeng-gh Mar 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is needed because DefaultValue does not work for BigInteger.

then this need 2 things,

  1. in the constructor to set it, which we already have.
  2. ShouldSerializeXXX to handle the serialization. #Closed


/// <summary>
/// Identifies the artifact and region.
Expand Down Expand Up @@ -155,7 +161,7 @@ private ISarifNode DeepCloneCore()
return new Location(this);
}

protected virtual void Init(int id, PhysicalLocation physicalLocation, IEnumerable<LogicalLocation> logicalLocations, Message message, IEnumerable<Region> annotations, IEnumerable<LocationRelationship> relationships, IDictionary<string, SerializedPropertyInfo> properties)
protected virtual void Init(BigInteger id, PhysicalLocation physicalLocation, IEnumerable<LogicalLocation> logicalLocations, Message message, IEnumerable<Region> annotations, IEnumerable<LocationRelationship> relationships, IDictionary<string, SerializedPropertyInfo> properties)
{
Id = id;
if (physicalLocation != null)
Expand Down Expand Up @@ -228,4 +234,4 @@ protected virtual void Init(int id, PhysicalLocation physicalLocation, IEnumerab
}
}
}
}
}
237 changes: 237 additions & 0 deletions src/Sarif/NotYetAutoGenerated/Location.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
// Copyright (c) Microsoft. All Rights Reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Numerics;
using System.Runtime.Serialization;

using Newtonsoft.Json;

namespace Microsoft.CodeAnalysis.Sarif
{
/// <summary>
/// A location within a programming artifact.
/// </summary>
[DataContract]
[GeneratedCode("Microsoft.Json.Schema.ToDotNet", "1.1.0.0")]
public partial class Location : PropertyBagHolder, ISarifNode
Copy link
Collaborator Author

@shaopeng-gh shaopeng-gh Mar 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Location

created a copy of the Location.cs to
NotYetAutoGenerated folder to make modification. #Closed

{
public static IEqualityComparer<Location> ValueComparer => LocationEqualityComparer.Instance;

public bool ValueEquals(Location other) => ValueComparer.Equals(this, other);
public int ValueGetHashCode() => ValueComparer.GetHashCode(this);

/// <summary>
/// Gets a value indicating the type of object implementing <see cref="ISarifNode" />.
/// </summary>
public virtual SarifNodeKind SarifNodeKind
{
get
{
return SarifNodeKind.Location;
}
}

/// <summary>
/// Value that distinguishes this location from all other locations within a single result object.
/// </summary>
[DataMember(Name = "id", IsRequired = false, EmitDefaultValue = false)]
[DefaultValue(-1)]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
public virtual BigInteger Id { get; set; }

public bool ShouldSerializeId()
{
return Id != -1;
}

/// <summary>
/// Identifies the artifact and region.
/// </summary>
[DataMember(Name = "physicalLocation", IsRequired = false, EmitDefaultValue = false)]
public virtual PhysicalLocation PhysicalLocation { get; set; }

/// <summary>
/// The logical locations associated with the result.
/// </summary>
[DataMember(Name = "logicalLocations", IsRequired = false, EmitDefaultValue = false)]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
public virtual IList<LogicalLocation> LogicalLocations { get; set; }

/// <summary>
/// A message relevant to the location.
/// </summary>
[DataMember(Name = "message", IsRequired = false, EmitDefaultValue = false)]
public virtual Message Message { get; set; }

/// <summary>
/// A set of regions relevant to the location.
/// </summary>
[DataMember(Name = "annotations", IsRequired = false, EmitDefaultValue = false)]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
public virtual IList<Region> Annotations { get; set; }

/// <summary>
/// An array of objects that describe relationships between this location and others.
/// </summary>
[DataMember(Name = "relationships", IsRequired = false, EmitDefaultValue = false)]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
public virtual IList<LocationRelationship> Relationships { get; set; }

/// <summary>
/// Key/value pairs that provide additional information about the location.
/// </summary>
[DataMember(Name = "properties", IsRequired = false, EmitDefaultValue = false)]
internal override IDictionary<string, SerializedPropertyInfo> Properties { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="Location" /> class.
/// </summary>
public Location()
{
Id = -1;
}

/// <summary>
/// Initializes a new instance of the <see cref="Location" /> class from the supplied values.
/// </summary>
/// <param name="id">
/// An initialization value for the <see cref="P:Id" /> property.
/// </param>
/// <param name="physicalLocation">
/// An initialization value for the <see cref="P:PhysicalLocation" /> property.
/// </param>
/// <param name="logicalLocations">
/// An initialization value for the <see cref="P:LogicalLocations" /> property.
/// </param>
/// <param name="message">
/// An initialization value for the <see cref="P:Message" /> property.
/// </param>
/// <param name="annotations">
/// An initialization value for the <see cref="P:Annotations" /> property.
/// </param>
/// <param name="relationships">
/// An initialization value for the <see cref="P:Relationships" /> property.
/// </param>
/// <param name="properties">
/// An initialization value for the <see cref="P:Properties" /> property.
/// </param>
public Location(int id, PhysicalLocation physicalLocation, IEnumerable<LogicalLocation> logicalLocations, Message message, IEnumerable<Region> annotations, IEnumerable<LocationRelationship> relationships, IDictionary<string, SerializedPropertyInfo> properties)
{
Init(id, physicalLocation, logicalLocations, message, annotations, relationships, properties);
}

/// <summary>
/// Initializes a new instance of the <see cref="Location" /> class from the specified instance.
/// </summary>
/// <param name="other">
/// The instance from which the new instance is to be initialized.
/// </param>
/// <exception cref="ArgumentNullException">
/// Thrown if <paramref name="other" /> is null.
/// </exception>
public Location(Location other)
{
if (other == null)
{
throw new ArgumentNullException(nameof(other));
}

Init(other.Id, other.PhysicalLocation, other.LogicalLocations, other.Message, other.Annotations, other.Relationships, other.Properties);
}

ISarifNode ISarifNode.DeepClone()
{
return DeepCloneCore();
}

/// <summary>
/// Creates a deep copy of this instance.
/// </summary>
public virtual Location DeepClone()
{
return (Location)DeepCloneCore();
}

private ISarifNode DeepCloneCore()
{
return new Location(this);
}

protected virtual void Init(BigInteger id, PhysicalLocation physicalLocation, IEnumerable<LogicalLocation> logicalLocations, Message message, IEnumerable<Region> annotations, IEnumerable<LocationRelationship> relationships, IDictionary<string, SerializedPropertyInfo> properties)
{
Id = id;
if (physicalLocation != null)
{
PhysicalLocation = new PhysicalLocation(physicalLocation);
}

if (logicalLocations != null)
{
var destination_0 = new List<LogicalLocation>();
foreach (var value_0 in logicalLocations)
{
if (value_0 == null)
{
destination_0.Add(null);
}
else
{
destination_0.Add(new LogicalLocation(value_0));
}
}

LogicalLocations = destination_0;
}

if (message != null)
{
Message = new Message(message);
}

if (annotations != null)
{
var destination_1 = new List<Region>();
foreach (var value_1 in annotations)
{
if (value_1 == null)
{
destination_1.Add(null);
}
else
{
destination_1.Add(new Region(value_1));
}
}

Annotations = destination_1;
}

if (relationships != null)
{
var destination_2 = new List<LocationRelationship>();
foreach (var value_2 in relationships)
{
if (value_2 == null)
{
destination_2.Add(null);
}
else
{
destination_2.Add(new LocationRelationship(value_2));
}
}

Relationships = destination_2;
}

if (properties != null)
{
Properties = new Dictionary<string, SerializedPropertyInfo>(properties);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Numerics;
using System.Reflection;

using Microsoft.Json.Schema;
Expand Down Expand Up @@ -161,7 +162,15 @@ private void PopulateInstanceWithDefaultMemberValues(ISarifNode node)
// we'll compute a default value based on the node type
if (defaultValue != null)
{
property.SetValue(node, defaultValue);
if (property.PropertyType == typeof(BigInteger))
{
property.SetValue(node, BigInteger.Parse(defaultValue.ToString()));
}
else
{
property.SetValue(node, defaultValue);
}

continue;
}
PopulatePropertyWithGeneratedDefaultValue(node, property);
Expand Down
Loading