@@ -117,6 +117,15 @@ private Version(VersionInfo info, boolean expired) {
117
117
public static Version getInstance () {
118
118
synchronized (staticLock ) {
119
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
+ }
120
129
return version ;
121
130
}
122
131
}
@@ -183,7 +192,7 @@ public static Version getInstance() {
183
192
* @return returns true if the AGPL version is used.
184
193
*/
185
194
public static boolean isAGPLVersion () {
186
- return getInstance ().getVersion (). indexOf ( AGPL ) > 0 ;
195
+ return getInstance ().isAGPL () ;
187
196
}
188
197
189
198
/**
@@ -246,6 +255,14 @@ public VersionInfo getInfo() {
246
255
return info ;
247
256
}
248
257
258
+ /**
259
+ * Checks if the current object has been initialized with AGPL license.
260
+ * @return returns true if the current object has been initialized with AGPL license.
261
+ */
262
+ private boolean isAGPL () {
263
+ return getVersion ().indexOf (AGPL ) > 0 ;
264
+ }
265
+
249
266
private static Version initDefaultLicensedVersion (String ownerName , String key ) {
250
267
String producer = producerLine + " (" + ownerName ;
251
268
if (! key .toLowerCase ().startsWith ("trial" )) {
@@ -270,7 +287,11 @@ private static Version initVersion(String producer, String key, boolean expired)
270
287
271
288
private static Class <?> getLicenseKeyClass () throws ClassNotFoundException {
272
289
String licenseKeyClassFullName = "com.itextpdf.licensekey.LicenseKey" ;
273
- return Class .forName (licenseKeyClassFullName );
290
+ return getClassFromLicenseKey (licenseKeyClassFullName );
291
+ }
292
+
293
+ private static Class <?> getClassFromLicenseKey (String classFullName ) throws ClassNotFoundException {
294
+ return Class .forName (classFullName );
274
295
}
275
296
276
297
private static void checkLicenseVersion (String coreVersionString , String licenseVersionString ){
@@ -360,4 +381,23 @@ private static Version atomicSetVersion(Version newVersion) {
360
381
return version ;
361
382
}
362
383
}
384
+
385
+ private static void licenseScheduledCheck () {
386
+ if (version .isAGPL ()) {
387
+ return ;
388
+ }
389
+
390
+ String licenseKeyProductFullName = "com.itextpdf.licensekey.LicenseKeyProduct" ;
391
+ String checkLicenseKeyMethodName = "scheduledCheck" ;
392
+ try {
393
+ Class <?> licenseKeyClass = getLicenseKeyClass ();
394
+ Class <?> licenseKeyProductClass = getClassFromLicenseKey (licenseKeyProductFullName );
395
+
396
+ Class [] cArg = {licenseKeyProductClass };
397
+ Method method = licenseKeyClass .getMethod (checkLicenseKeyMethodName , cArg );
398
+ method .invoke (null , new Object []{null });
399
+ } catch (Exception e ) {
400
+ throw new RuntimeException (e .getMessage (), e );
401
+ }
402
+ }
363
403
}
0 commit comments