diff --git a/rhino/src/main/java/org/mozilla/classfile/ClassFileWriter.java b/rhino/src/main/java/org/mozilla/classfile/ClassFileWriter.java index 106d0063c5..f2f7ab29aa 100644 --- a/rhino/src/main/java/org/mozilla/classfile/ClassFileWriter.java +++ b/rhino/src/main/java/org/mozilla/classfile/ClassFileWriter.java @@ -4367,21 +4367,31 @@ private void finalizeSuperBlockStarts() { // Based on the version numbers we scrape, we can also determine what // bytecode features we need. For example, Java 6 bytecode (classfile // version 50) should have stack maps generated. + int minor = 0; + int major = 48; try (InputStream is = readClassFile()) { - byte[] header = new byte[8]; - // read loop is required since JDK7 will only provide 2 bytes - // on the first read() - see bug #630111 - int read = 0; - while (read < 8) { - int c = is.read(header, read, 8 - read); - if (c < 0) throw new IOException(); - read += c; + if (is != null) { + byte[] header = new byte[8]; + // read loop is required since JDK7 will only provide 2 bytes + // on the first read() - see bug #630111 + int read = 0; + while (read < 8) { + int c = is.read(header, read, 8 - read); + if (c < 0) throw new IOException(); + read += c; + } + minor = (header[4] << 8) | (header[5] & 0xff); + major = (header[6] << 8) | (header[7] & 0xff); + } else { + System.err.println( + "Warning: Unable to read ClassFileWriter.class, using default bytecode version"); } - MinorVersion = (header[4] << 8) | (header[5] & 0xff); - MajorVersion = (header[6] << 8) | (header[7] & 0xff); - GenerateStackMap = MajorVersion >= 50; } catch (IOException ioe) { throw new AssertionError("Can't read ClassFileWriter.class to get bytecode version"); + } finally { + MinorVersion = minor; + MajorVersion = major; + GenerateStackMap = MajorVersion >= 50; } } diff --git a/rhino/src/main/java/org/mozilla/javascript/JavaMembers.java b/rhino/src/main/java/org/mozilla/javascript/JavaMembers.java index cefb97100f..abd9caa513 100644 --- a/rhino/src/main/java/org/mozilla/javascript/JavaMembers.java +++ b/rhino/src/main/java/org/mozilla/javascript/JavaMembers.java @@ -328,7 +328,8 @@ private void discoverAccessibleMethods( if (isPublic(mods) || isProtected(mods) || includePrivate) { MethodSignature sig = new MethodSignature(method); if (!map.containsKey(sig)) { - if (includePrivate) method.trySetAccessible(); + if (includePrivate && !method.isAccessible()) + method.setAccessible(true); map.put(sig, method); } } @@ -667,7 +668,7 @@ private Field[] getAccessibleFields(boolean includeProtected, boolean includePri for (Field field : declared) { int mod = field.getModifiers(); if (includePrivate || isPublic(mod) || isProtected(mod)) { - field.trySetAccessible(); + if (!field.isAccessible()) field.setAccessible(true); fieldsList.add(field); } }