@@ -109,27 +109,31 @@ public Version() {
109
109
110
110
/**
111
111
* Gets an instance of the iText version that is currently used.
112
+ *
112
113
* <p>
113
114
* Note that iText Group requests that you retain the iText producer line
114
115
* in every PDF that is created or manipulated using iText.
115
116
* @return an instance of {@link Version}.
116
117
*/
117
118
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 );
130
135
}
131
136
}
132
- Version localVersion ;
133
137
String key = null ;
134
138
try {
135
139
String coreVersion = release ;
@@ -386,8 +390,8 @@ private static Version atomicSetVersion(Version newVersion) {
386
390
}
387
391
}
388
392
389
- private static void licenseScheduledCheck () {
390
- if (version .isAGPL ()) {
393
+ private static void licenseScheduledCheck (Version localVersion ) {
394
+ if (localVersion .isAGPL ()) {
391
395
return ;
392
396
}
393
397
0 commit comments