#1 2025-11-04 11:41:22

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 477

variable that is nil is used and cause exception

mormot.core.collections, line 902

if fDynArray.Info.ArrayRtti is nil then fDynArray.Info.ArrayRtti.Kind will cause exception
I have random errors from that

constructor TIListParent.CreateRtti(aDynArray: TRttiCustom;
  aItemTypeInfo: PRttiInfo; aOptions: TListOptions; aSortAs: TRttiParserType);
begin
  fDynArray.InitRtti(aDynArray, fValue, @fCount);
  aSortAs := fDynArray.SetParserType(aSortAs, // aSortAs=ptNone->RTTI
    loCaseInsensitive in fOptions);
  if (fDynArray.Info.ArrayRtti = nil) or
     (fDynArray.Info.ArrayRtti.Kind <> aItemTypeInfo^.Kind)  then
    EIList.RaiseUtf8('%.Create<%> (%) does not match % (%)',
      [self, aItemTypeInfo^.RawName, ToText(aItemTypeInfo^.Kind)^,
       aDynArray.Info^.RawName, ToText(fDynArray.Info.ArrayRtti.Kind)^]);

Offline

#2 2025-11-04 16:13:22

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,261
Website

Re: variable that is nil is used and cause exception

Which compiler?
Which array type?

I guess there is not enough RTTI for this.

Offline

#3 2025-11-04 21:56:59

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 477

Re: variable that is nil is used and cause exception

@ab, Delphi 11.3 in a Torm class
but:
if (fDynArray.Info.ArrayRtti = nil) or
     (fDynArray.Info.ArrayRtti.Kind <> aItemTypeInfo^.Kind)  then
    EIList.RaiseUtf8('%.Create<%> (%) does not match % (%)',
      [self, aItemTypeInfo^.RawName, ToText(aItemTypeInfo^.Kind)^,
       aDynArray.Info^.RawName, ToText(fDynArray.Info.ArrayRtti.Kind)^]);

Offline

#4 2025-11-05 07:40:51

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,261
Website

Re: variable that is nil is used and cause exception

I still don't understand how you defined the IList instance.

Offline

#5 2025-11-05 09:19:29

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 477

Re: variable that is nil is used and cause exception

Apologies Ab, I did not define anything new
I noticed that this happens since the updates in github after 3/11/25
The exception I get is in EIList.RaiseUtf8 and when debugging the fDynArray.Info.ArrayRtti is nil

Offline

#6 2025-11-05 09:52:25

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 477

Re: variable that is nil is used and cause exception

ab wrote:

I still don't understand how you defined the IList instance.

I was using NewPlainList instead of NewList, as I notice now.
But still, in the above code if fDynArray.Info.ArrayRtti = nil, then the fDynArray.Info.ArrayRtti.Kind in EIList.RaiseUtf8 will give exception

Offline

#7 Yesterday 13:37:22

sgavrilov
Member
Registered: 2019-05-24
Posts: 24

Re: variable that is nil is used and cause exception

I have got it! smile

There is a bug in this statement: if the ArrayRtti property is nil (by any reason) then the condition in the "if" statement is fine due to the short-circuit evaluation. But then the EIList.RaiseUtf8() is called and the ArrayRtti.Kind is used as a parameter value!

Offline

#8 Yesterday 15:58:15

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 477

Re: variable that is nil is used and cause exception

ab wrote:

I still don't understand how you defined the IList instance.

TormGetbundle=class(Torm)
    private
      Fdedo: RawUtf8;   Fupddat: tdatetime;    Ftyp,Fekdosi: integer;
    public
      class procedure InitializeTable(const Server: IRestOrmServer; const FieldName: RawUtf8; Options: TOrmInitializeTableOptions); override;
    published
      property typ:integer read Ftyp write Ftyp;           
      property ekdosi:integer read Fekdosi write Fekdosi;
      property dedo:RawUtf8 read Fdedo write Fdedo;     
      property upddat:tdatetime read Fupddat write Fupddat;
  end;

The errors happens when I do the following:
lis:=collections.NewList<TormGetbundle>;

TormGetbundle in this windows app is not an db table, (part of shared code with an other app that uses it as db table)

Offline

Board footer

Powered by FluxBB