Building my plugin failing with maven enforce rules for messages class and previous and next methods of corntablist class

Building plugin failing with maven enforce rules for messages class and previous and next methods of corntablist class. Building plugin was successfull with java 8 and jenkins 2.62 version, getting the following errors with jenkins 2.361.4 and java 11. Any help to solve these issues and build plugin is greatly appreciated.
Error Log: [INFO] β€” maven-compiler-plugin:3.10.1:compile (default-compile) @ buildparameters β€”
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 33 source files to C:\Users\bonthu.sirisha\OneDrive - HCL Technologies Ltd\Desktop\Security Vulnerabilities Or WhiteSource\kony-jenkins-buildparameters-plugin\target\classes
[INFO]
[INFO] β€” access-modifier-checker:1.29:enforce (default-enforce) @ buildparameters β€”
[ERROR] com/kony/AppFactory/Jenkins/parameters/cron/CronParameterDefinition$DescriptorImpl:115 hudson/triggers/Messages must not be used
[ERROR] com/kony/AppFactory/Jenkins/parameters/cron/CronParameterDefinition$DescriptorImpl:133 hudson/scheduler/CronTabList.previous()Ljava/util/Calendar; must not be used
[ERROR] com/kony/AppFactory/Jenkins/parameters/cron/CronParameterDefinition$DescriptorImpl:134 hudson/scheduler/CronTabList.next()Ljava/util/Calendar; must not be used
[ERROR] com/kony/AppFactory/Jenkins/parameters/cron/CronParameterDefinition$DescriptorImpl:137 hudson/triggers/Messages must not be used
[ERROR] com/kony/AppFactory/Jenkins/parameters/cron/CronParameterDefinition$DescriptorImpl:140 hudson/triggers/Messages must not be used
[ERROR] com/kony/AppFactory/Jenkins/parameters/cron/CronParameterDefinition$DescriptorImpl:144 hudson/triggers/Messages must not be used
[ERROR] com/kony/AppFactory/Jenkins/parameters/cron/CronParameterValue:96 hudson/scheduler/CronTabList.previous()Ljava/util/Calendar; must not be used
[ERROR] com/kony/AppFactory/Jenkins/parameters/cron/CronParameterValue:97 hudson/scheduler/CronTabList.next()Ljava/util/Calendar; must not be used
[ERROR] com/kony/AppFactory/Jenkins/parameters/cron/CronParameterValue:118 hudson/triggers/Messages must not be used
[ERROR] com/kony/AppFactory/Jenkins/parameters/cron/CronParameterValue:127 hudson/triggers/Messages must not be used

The error message already describes the problem: in your classes you are using messages that are internal implementation details of Jenkins core. This was not checked in very old Jenkins versions.

You must provide your own messages to fix the error. See Prepare a Java Source File for Localization for details.

1 Like

Thank you, I followed Localization for messages. Any alternatives I can go for methods CornTabList.previous()Ljava/util/Calendar and CronTabList.next()Ljava/util/Calendar?

There isn’t an alternative for CronTabList.previous() or for CronTabList.next(). The CronTabList object is not intended to have its contents available to Java consumers. The next() and previous() methods are marked as NoExternalUse as a way to prevent Java consumers from calling those methods. They have been marked that way since 2014. They are public so that they can be called by the form validation system in Jenkins.

You’ll need to replace your use of the CronTabList object contents either with calls to CronTabList.check(Calendar) or use a different data structure to represent the concept in your code.

1 Like

Thank you for valuable suggestions, will try on it.

I used both methods in ValidationsForNextRun method as below, able to build plugin successfully without any issues. Can I go with this approach or any other?
private void updateValidationsForNextRun(Collection validations, CronTabList ctl) {
try {
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();

        ScheduledFuture<?> prevFuture = executor.schedule(() -> {
            Calendar prev = ctl.previous();
			return prev ;
        }, 0, TimeUnit.SECONDS);

        ScheduledFuture<?> nextFuture = executor.schedule(() -> {
            Calendar next = ctl.next();
			return next ;
        }, 0, TimeUnit.SECONDS);
        try {
            Calendar prev = (Calendar) prevFuture.get();
            Calendar next = (Calendar) nextFuture.get();
			if (prev != null && next != null) {
                DateFormat fmt = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);
                validations.add(FormValidation.ok(Messages.TimerTrigger_would_last_have_run_at_would_next_run_at(fmt.format(prev.getTime()), fmt.format(next.getTime()))));
            } else {
                validations.add(FormValidation.warning(Messages.TimerTrigger_no_schedules_so_will_never_run()));
            }
        } catch (Exception ex) {
            validations.add(FormValidation.warning(Messages.TimerTrigger_the_specified_cron_tab_is_rare_or_impossible()));
        } finally {
            executor.shutdown();
        }
    } catch (Exception e) {
        // Handle exceptions related to the scheduling or executor
    }
}
}

Also now why it is not throwing any error when used with executor service?