@@ -116,22 +116,24 @@ internal Version(VersionInfo info, bool expired) {
116116 /// <see cref="Version"/>.
117117 /// </returns>
118118 public static iText . Kernel . Version GetInstance ( ) {
119- lock ( staticLock ) {
120- if ( version != null ) {
121- try {
122- LicenseScheduledCheck ( ) ;
123- }
124- catch ( Exception e ) {
125- // If any exception occurs during scheduled check of core license,
126- // then it means that license is not valid yet, so roll back to AGPL.
127- // The key value is null as it is similar to case
128- // when an exception has been thrown during initial license loading
129- AtomicSetVersion ( InitAGPLVersion ( e , null ) ) ;
130- }
131- return version ;
119+ iText . Kernel . Version localVersion = version ;
120+ // It's crucial to work with 'localVersion' local variable, because 'version' field can be
121+ // changed by some other thread. We also don't want to block Version class lock when calling
122+ // for scheduled check in order to avoid synchronization issues with parallel loading license.
123+ if ( localVersion != null ) {
124+ try {
125+ LicenseScheduledCheck ( localVersion ) ;
126+ return localVersion ;
127+ }
128+ catch ( Exception e ) {
129+ // If any exception occurs during scheduled check of core license it means that
130+ // license is not valid, in this particular case we want to reset to AGPL Version,
131+ // however "normal" initialization logic will not switch to AGPL unless license is
132+ // unloaded.
133+ // not saving this AGPL version in order to avoid race condition with loaded proper license
134+ return InitAGPLVersion ( e , null ) ;
132135 }
133136 }
134- iText . Kernel . Version localVersion ;
135137 String key = null ;
136138 try {
137139 String coreVersion = release ;
@@ -418,8 +420,8 @@ private static iText.Kernel.Version AtomicSetVersion(iText.Kernel.Version newVer
418420 }
419421 }
420422
421- private static void LicenseScheduledCheck ( ) {
422- if ( version . IsAGPL ( ) ) {
423+ private static void LicenseScheduledCheck ( iText . Kernel . Version localVersion ) {
424+ if ( localVersion . IsAGPL ( ) ) {
423425 return ;
424426 }
425427 String licenseKeyProductFullName = "iText.License.LicenseKeyProduct, itext.licensekey" ;
0 commit comments