@@ -109,27 +109,31 @@ public Version() {
109109
110110 /**
111111 * Gets an instance of the iText version that is currently used.
112+ *
112113 * <p>
113114 * Note that iText Group requests that you retain the iText producer line
114115 * in every PDF that is created or manipulated using iText.
115116 * @return an instance of {@link Version}.
116117 */
117118 public static Version getInstance () {
118- synchronized (staticLock ) {
119- if (version != null ) {
120- try {
121- licenseScheduledCheck ();
122- } catch (Exception e ) {
123- // If any exception occurs during scheduled check of core license,
124- // then it means that license is not valid yet, so roll back to AGPL.
125- // The key value is null as it is similar to case
126- // when an exception has been thrown during initial license loading
127- atomicSetVersion (initAGPLVersion (e , null ));
128- }
129- return version ;
119+ 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+ } catch (Exception e ) {
128+ // If any exception occurs during scheduled check of core license it means that
129+ // license is not valid, in this particular case we want to reset to AGPL Version,
130+ // however "normal" initialization logic will not switch to AGPL unless license is
131+ // unloaded.
132+
133+ // not saving this AGPL version in order to avoid race condition with loaded proper license
134+ return initAGPLVersion (e , null );
130135 }
131136 }
132- Version localVersion ;
133137 String key = null ;
134138 try {
135139 String coreVersion = release ;
@@ -386,8 +390,8 @@ private static Version atomicSetVersion(Version newVersion) {
386390 }
387391 }
388392
389- private static void licenseScheduledCheck () {
390- if (version .isAGPL ()) {
393+ private static void licenseScheduledCheck (Version localVersion ) {
394+ if (localVersion .isAGPL ()) {
391395 return ;
392396 }
393397
0 commit comments