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

Fix null ref exception when repo has empty ckan file #2549

Merged
merged 1 commit into from
Oct 28, 2018

Conversation

HebaruSan
Copy link
Member

Problem

If you refresh the registry and the remote repo contains an empty .ckan file, you may see exceptions with stack traces like these:

   bei CKAN.Repo.ProcessRegistryMetadataFromJSON(String metadata, Registry registry, String filename) in C:\Users\Martin\Documents\Visual Studio 2015\Projects\CKAN\Core\Net\Repo.cs:Zeile 69.
   bei CKAN.Repo.UpdateRegistryFromZip(String path, Registry registry) in C:\Users\Martin\Documents\Visual Studio 2015\Projects\CKAN\Core\Net\Repo.cs:Zeile 383.
   bei CKAN.Repo.UpdateRegistry(Uri repo, Registry registry, KSP ksp, IUser user, Boolean clear) in C:\Users\Martin\Documents\Visual Studio 2015\Projects\CKAN\Core\Net\Repo.cs:Zeile 161.
   bei CKAN.Repo.UpdateAllRepositories(RegistryManager registry_manager, KSP ksp, IUser user) in C:\Users\Martin\Documents\Visual Studio 2015\Projects\CKAN\Core\Net\Repo.cs:Zeile 89.
   bei CKAN.Main.UpdateRepo(Object sender, DoWorkEventArgs e) in C:\Users\Martin\Documents\Visual Studio 2015\Projects\CKAN\GUI\MainRepo.cs:Zeile 62.
************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
   at CKAN.Main.UpdateRepo()
   at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
   at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ToolStrip.WndProc(Message& m)
   at System.Windows.Forms.MenuStrip.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Causes

An empty file would cause the first line here to return null:

CKAN/Core/Net/Repo.cs

Lines 550 to 551 in b9a91fa

CkanModule module = CkanModule.FromJson(metadata);
log.DebugFormat("Found {0} version {1}", module.identifier, module.version);

If that happens, then the second line still tries to access a property on the null reference.

Changes

Now we skip that debug output if the reference is null.

Fixes #1381.

@HebaruSan HebaruSan added Bug Something is not working as intended Easy This is easy to fix Core (ckan.dll) Issues affecting the core part of CKAN Pull request Registry Issues affecting the registry labels Oct 23, 2018
@Olympic1 Olympic1 merged commit bdc2f76 into KSP-CKAN:master Oct 28, 2018
@HebaruSan HebaruSan deleted the fix/empty-ckan-nre branch October 28, 2018 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is not working as intended Core (ckan.dll) Issues affecting the core part of CKAN Easy This is easy to fix Registry Issues affecting the registry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants