Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8240734

ModuleHashes attribute not reproducible between builds

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 15
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b14
    • CPU:
      generic
    • OS:
      generic

      Description

      We see some inconsistency of module-info.class in java.base.jmod across different builds.

      $ jmod extract java.base.jmod
      $ cd classes
      $ javap -v module-info.class


      $ diff old-class.info new-class.info
      1c1
      < Classfile /home/sunjianye/bep_compare/old/classes/module-info.class
      ---
      > Classfile /home/sunjianye/bep_compare/new/classes/module-info.class
      3c3
      < MD5 checksum f76c99747727a55976dca003d1bc8faa
      ---
      > MD5 checksum 701d2aee48a029f896f426dde5fd5cb3
      1130,1132d1129
      < #527 // java.transaction.xa
      < hash_length: 32
      < hash: [d3caeb7d503e86206fbfc08aa88f0a491eb2c3cd984575e3b8069575406c6af0]
      1138a1136,1138
      > #527 // java.transaction.xa
      > hash_length: 32
      > hash: [d3caeb7d503e86206fbfc08aa88f0a491eb2c3cd984575e3b8069575406c6af0]


      Proposed fix:

      diff -r 3437fb6311fd src/java.base/share/classes/jdk/internal/module/ModuleHashes.java
      --- a/src/java.base/share/classes/jdk/internal/module/ModuleHashes.java Mon Mar 09 04:06:37 2020 -0400
      +++ b/src/java.base/share/classes/jdk/internal/module/ModuleHashes.java Mon Mar 09 17:53:12 2020 +0800
      @@ -1,5 +1,5 @@
       /*
      - * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
      + * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
        * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
        *
        * This code is free software; you can redistribute it and/or modify it
      @@ -34,6 +34,7 @@
       import java.security.NoSuchAlgorithmException;
       import java.util.Collections;
       import java.util.HashMap;
      +import java.util.TreeMap;
       import java.util.Map;
       import java.util.Objects;
       import java.util.Set;
      @@ -134,7 +135,7 @@
            * @return ModuleHashes that encapsulates the hashes
            */
           public static ModuleHashes generate(Map<String, Path> map, String algorithm) {
      - Map<String, byte[]> nameToHash = new HashMap<>();
      + Map<String, byte[]> nameToHash = new TreeMap<>();
               for (Map.Entry<String, Path> entry: map.entrySet()) {
                   String name = entry.getKey();
                   Path path = entry.getValue();
      diff -r 3437fb6311fd src/java.base/share/classes/jdk/internal/module/ModuleHashesBuilder.java
      --- a/src/java.base/share/classes/jdk/internal/module/ModuleHashesBuilder.java Mon Mar 09 04:06:37 2020 -0400
      +++ b/src/java.base/share/classes/jdk/internal/module/ModuleHashesBuilder.java Mon Mar 09 17:53:12 2020 +0800
      @@ -1,5 +1,5 @@
       /*
      - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
      + * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
        * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
        *
        * This code is free software; you can redistribute it and/or modify it
      @@ -34,6 +34,7 @@
       import java.util.Collections;
       import java.util.Deque;
       import java.util.HashMap;
      +import java.util.TreeMap;
       import java.util.HashSet;
       import java.util.Map;
       import java.util.Set;
      @@ -98,7 +99,7 @@
               // the modules to record the hashes - it is the first matching
               // module and has not been hashed during the traversal.
               Set<String> mods = new HashSet<>();
      - Map<String, ModuleHashes> hashes = new HashMap<>();
      + Map<String, ModuleHashes> hashes = new TreeMap<>();
               builder.build()
                      .orderedNodes()
                      .filter(mn -> roots.contains(mn) && !mods.contains(mn))

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                fyang Fei Yang
                Reporter:
                fyang Fei Yang
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: