Skip to content

fix: Improve null safety in BundleGenerator #711

@tyevco

Description

@tyevco

Summary

BundleGenerator has null safety issues that can cause generator crashes.

Source: Code Review #705 (Issues 3, 6)

Issues

1. Force Unwrap on FirstOrDefault

Location: editor/KeenEyes.Generators/BundleGenerator.cs:300

// CURRENT - force unwrap can throw NRE:
typeSymbol.Locations.FirstOrDefault()!

// SHOULD BE:
var location = typeSymbol.Locations.FirstOrDefault();
if (location == null) return; // or use default location

2. Dangerous String Substring

Location: editor/KeenEyes.Generators/BundleGenerator.cs:1188

// CURRENT - assumes namespace exists:
var bundleName = typeToRemove.Substring(typeToRemove.LastIndexOf('.') + 1);

// SHOULD BE:
var lastDot = typeToRemove.LastIndexOf('.');
var bundleName = lastDot >= 0 ? typeToRemove.Substring(lastDot + 1) : typeToRemove;

Impact

Generator crashes for edge cases (global namespace types, types without source location).

Priority

HIGH - Generator stability.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions