NoClassDefFoundError Being Encountered Intermittently When Using ZoneRulesProvider

一笑奈何 提交于 2020-02-29 08:05:37

问题


I know that this is somehow similar to this question, but the answer there doesn't seem to help me. But I am also encountering the same issue.. here's a snippet of the logs,

java.lang.NoClassDefFoundError: Could not initialize class 
java.time.zone.ZoneRulesProvider
java.time.ZoneRegion.ofId(ZoneRegion.java:120)
java.time.ZoneId.of(ZoneId.java:411)
java.time.ZoneId.of(ZoneId.java:359)
java.time.ZoneId.of(ZoneId.java:315)
java.util.TimeZone.toZoneId(TimeZone.java:556)
java.time.ZoneId.systemDefault(ZoneId.java:274)

And it seems like it's coming from using ZoneId.systemDefault() in my utility method,

    public  static String formatDate(Date date) {
        if(Objects.nonNull(date)) {
            LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
            return localDate.format(<some_formats_here>);
        }

        return null;
    }

The environment is using,

openjdk version "1.8.0_242"
OpenJDK Runtime Environment (build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)

Any help would be appreciated!

By the way, this occurs intermittently and happens after deploying the latest codes to the server. I have not encountered it in my local machine's build even though the environment set up are the same with production environment.

Thanks!


回答1:


Turns out that JVM_HOME must be declared on a system level according to my colleague. This part of code was the one spitting up the problem:

try {
            String libDir = System.getProperty("java.home") + File.separator + "lib";
            try (DataInputStream dis = new DataInputStream(
                     new BufferedInputStream(new FileInputStream(
                         new File(libDir, "tzdb.dat"))))) {
                load(dis);
            }
        } catch (Exception ex) {
            throw new ZoneRulesException("Unable to load TZDB time-zone rules", ex);
        }

Unfortunately I can't really elaborate on how it was really solved but so far it worked for us. Might help others.



来源:https://stackoverflow.com/questions/60272893/noclassdeffounderror-being-encountered-intermittently-when-using-zonerulesprovid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!