JuliaIO / JLD.jl

Saving and loading julia variables while preserving native types
MIT License
277 stars 55 forks source link

Nullables can cause UndefRefErrors #47

Open jrevels opened 8 years ago

jrevels commented 8 years ago
julia> JLD.save("test.jld", "x", Nullable{UTF8String}())
ERROR: UndefRefError: access to undefined reference
 in write_compound at /Users/jarrettrevels/.julia/v0.4/JLD/src/JLD.jl:683
 in write at /Users/jarrettrevels/.julia/v0.4/JLD/src/JLD.jl:504
 in anonymous at /Users/jarrettrevels/.julia/v0.4/JLD/src/JLD.jl:1165
 in jldopen at /Users/jarrettrevels/.julia/v0.4/JLD/src/JLD.jl:240
 in save at /Users/jarrettrevels/.julia/v0.4/JLD/src/JLD.jl:1163
 in save at /Users/jarrettrevels/.julia/v0.4/FileIO/src/loadsave.jl:51

This is because the value of the Nullable is #undef:

julia> dump(Nullable{UTF8String}())
Nullable{UTF8String}
  isnull: Bool true
  value: #undef

Note, then, that types which initialize with values are unaffected, e.g. numeric primitives:

julia> dump(Nullable{Float64}())
Nullable{Float64}
  isnull: Bool true
  value: Float64 2.151511976e-314

julia> JLD.save("test.jld", "x", Nullable{Float64}()) # works fine
simonster commented 8 years ago

This is most likely specific to undefined string fields. It doesn't happen with arbitrary non-pointerfree types. I'm not sure whether libhdf5 would let us specify an undefined string field using a null pointer, but we could try. JLD2 handles this properly, but I've been swamped with work recently and haven't been able to finish it (which basically means implementing compression; everything else works).