CODETOOLS-7902549 Asmtools processes Runtime{In}VisibleTypeAnnotations incorrectly

CODETOOLS-7902563 jdec: wrong interpretation of the module_name_index in the Module attribute
Codebase, build updated to support JDK 8
This commit is contained in:
lkuskov 2020-01-06 13:12:12 -08:00
parent 187e90eb4a
commit a136ef54ee
14 changed files with 65 additions and 66 deletions

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2014, 2019, 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
@ -251,8 +251,8 @@ Other values for TARGET are:
<target name="compileClasses" depends="prepare">
<mkdir dir="${build.classes.dir}"/>
<javac fork="true"
target="9"
source="9"
target="1.8"
source="1.8"
srcdir="${build.src.classes.dir}"
destdir="${build.classes.dir}"
debug="${javac.debug}"

@ -27,5 +27,5 @@ PRODUCT_NAME = asmtools
PRODUCT_JAR_NAME = asmtools.jar
PRODUCT_VERSION = 7.0
PRODUCT_MILESTONE = beta
PRODUCT_BUILDNUMBER = b01
PRODUCT_BUILDNUMBER = b02
PRODUCT_NAME_LONG = Java Assembler Tools

@ -48,7 +48,6 @@ class FieldData extends MemberData {
return nape;
}
public void SetValue(Argument value_cpx) {
initValue = new CPXAttr(cls, AttrTag.ATT_ConstantValue.parsekey(),
value_cpx);
@ -56,17 +55,7 @@ class FieldData extends MemberData {
@Override
protected DataVector getAttrVector() {
return getDataVector( new ArrayList<>(){{
if (initValue != null) {
add(initValue);
};
if (syntheticAttr != null) {
add(syntheticAttr);
}
if (deprecatedAttr != null) {
add(deprecatedAttr);
}
}} );
return getDataVector(initValue, syntheticAttr, deprecatedAttr);
}
public void write(CheckedDataOutputStream out) throws IOException, Parser.CompilerError {

@ -65,6 +65,10 @@ public class Main extends Tool {
error( i18n.getString("jasm.error.cannot_read", fname));
}
public Main(PrintStream out, String program) {
this(new PrintWriter(out), program);
}
@Override
public void usage() {
println(i18n.getString("jasm.usage"));

@ -75,11 +75,14 @@ abstract public class MemberData {
protected abstract DataVector getAttrVector();
protected final DataVector getDataVector(List<Data> extraAttrs) {
protected final DataVector getDataVector(Data... extraAttrs) {
DataVector attrs = new DataVector();
if (extraAttrs != null) {
attrs.addAll(extraAttrs);
for( Data extra : extraAttrs ) {
if (extra != null) {
attrs.add(extra);
}
}
// common set for [ FieldData, MethodData, RecordData ]
if (annotAttrVis != null) {
attrs.add(annotAttrVis);
}

@ -26,6 +26,7 @@ import org.openjdk.asmtools.jasm.Tables.AttrTag;
import org.openjdk.asmtools.jasm.ConstantPool.ConstCell;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;
/**
@ -206,35 +207,13 @@ class MethodData extends MemberData {
@Override
protected DataVector getAttrVector() {
DataVector dv = getDataVector( new ArrayList<>(){{
if (exceptions != null) {
add(exceptions);
}
if (syntheticAttr != null) {
add(syntheticAttr);
}
if (deprecatedAttr != null) {
add(deprecatedAttr);
}
if (paramNames != null) {
add(paramNames);
}
if (code != null) {
add(code);
}
if (defaultAnnot != null) {
add(defaultAnnot);
}
}});
dv.addAll(
new ArrayList<>() {{
if (pannotAttrVis != null) {
add(pannotAttrVis);
}
if (pannotAttrInv != null) {
add(pannotAttrInv);
}
}});
DataVector dv = getDataVector( exceptions, syntheticAttr, deprecatedAttr, paramNames, code, defaultAnnot);
if (pannotAttrVis != null) {
dv.add(pannotAttrVis);
}
if (pannotAttrInv != null) {
dv.add(pannotAttrInv);
}
return dv;
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2019, 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
@ -22,6 +22,8 @@
*/
package org.openjdk.asmtools.jasm;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
@ -417,10 +419,10 @@ public class Modifiers {
sb.append(Token.ABSTRACT.parsekey() + " ");
}
}
if ( Set.of(CF_Context.CTX_CLASS, CF_Context.CTX_INNERCLASS, CF_Context.CTX_FIELD).contains(context) && isFinal(mod)) {
if ( context.isOneOf(CF_Context.CTX_CLASS, CF_Context.CTX_INNERCLASS, CF_Context.CTX_FIELD) && isFinal(mod)) {
sb.append(Token.FINAL.parsekey() + " ");
}
if (Set.of(CF_Context.CTX_CLASS, CF_Context.CTX_INNERCLASS).contains(context) && isInterface(mod)) {
if (context.isOneOf(CF_Context.CTX_CLASS, CF_Context.CTX_INNERCLASS) && isInterface(mod)) {
if (isAnnotation(mod)) {
sb.append(Token.ANNOTATION_ACCESS.parsekey() + " ");
}
@ -438,7 +440,7 @@ public class Modifiers {
if (isEnum(mod)) {
sb.append(Token.ENUM.parsekey() + " ");
}
if (Set.of(CF_Context.CTX_METHOD, CF_Context.CTX_FIELD).contains(context) && isMandated(mod)) {
if (context.isOneOf(CF_Context.CTX_METHOD, CF_Context.CTX_FIELD) && isMandated(mod)) {
sb.append(Token.MANDATED.parsekey() + " ");
}

@ -66,7 +66,7 @@ public class RecordData extends AttrData {
@Override
public int attrLength() {
int compsLength = components.stream().mapToInt(c -> c.getLength()).sum();
int compsLength = components.stream().mapToInt(c -> c.getLength()).sum();
return 2 + compsLength;
}
@ -85,11 +85,7 @@ public class RecordData extends AttrData {
@Override
protected DataVector getAttrVector() {
return getDataVector(new ArrayList<>() {{
if (signature != null) {
add(signature);
}
}});
return getDataVector(signature);
}
public void write(CheckedDataOutputStream out) throws IOException, Parser.CompilerError {

@ -644,7 +644,7 @@ public class Tables {
/**
* CF_Context enums
*/
static public enum CF_Context {
public enum CF_Context {
CTX_CLASS (0, "class"),
CTX_FIELD (1, "field"),
@ -660,6 +660,15 @@ public class Tables {
printval = print;
}
boolean isOneOf(CF_Context... items) {
for(CF_Context item : items) {
if(item.value == value) {
return true;
}
}
return false;
}
public int val() {
return value;
}

@ -26,10 +26,7 @@ import org.openjdk.asmtools.common.Tool;
import org.openjdk.asmtools.util.I18NResourceBundle;
import org.openjdk.asmtools.util.ProductInfo;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
@ -49,6 +46,10 @@ public class Main extends Tool {
};
}
public Main(PrintStream out, String program) {
this(new PrintWriter(out), program);
}
@Override
public void usage() {
println(i18n.getString("jcoder.usage"));

@ -43,7 +43,7 @@ jcoder.error.fatal_error=fatal error
jcoder.error.fatal_exception=fatal exception
err.eof.in.comment=Comment not terminated at end of input.
err.invalid.number=Invalid character '{0}' in number.
err.invalid.number=Invalid character '%s' in number.
#err.invalid.octal.number=Invalid character in octal number.
err.overflow=Numeric overflow.
#err.float.format=Invalid floating point format.

@ -503,7 +503,7 @@ class ClassData {
}
// [4.7.20.2]
int path_length = in.readUnsignedByte(); // type_path { u1 path_length; ...}
startArrayCmt(path_length, "type_paths");
startArrayCmtB(path_length, "type_paths");
try {
for (int i = 0; i < path_length; i++) {
// print the type_path elements
@ -1078,7 +1078,13 @@ class ClassData {
private void decodeModule(DataInputStream in) throws IOException {
//u2 module_name_index
int index = in.readUnsignedShort();
printUtf8InfoIndex((Integer)cpool[index], "name_index");
entityName = (String) cpool[(Integer) cpool[index]];
out_print("#" + index + "; // ");
if (printDetails) {
out.println(String.format("%-16s","name_index") + " : " + entityName);
} else {
out.println("name_index");
}
// u2 module_flags
int moduleFlags = in.readUnsignedShort();

@ -28,6 +28,7 @@ import org.openjdk.asmtools.util.I18NResourceBundle;
import org.openjdk.asmtools.util.ProductInfo;
import java.io.DataInputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.ArrayList;
@ -47,6 +48,10 @@ public class Main extends Tool {
error( i18n.getString("jdec.error.cannot_read", fname));
}
public Main(PrintStream out, String program) {
this(new PrintWriter(out), new PrintWriter(System.err), program);
}
@Override
public void usage() {
println(i18n.getString("jdec.usage"));

@ -27,6 +27,7 @@ import org.openjdk.asmtools.util.I18NResourceBundle;
import org.openjdk.asmtools.util.ProductInfo;
import java.io.DataInputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.ArrayList;
@ -48,6 +49,10 @@ public class Main extends Tool {
printCannotReadMsg = (fname) -> error( i18n.getString("jdis.error.cannot_read", fname));
}
public Main(PrintStream out, String program) {
this(new PrintWriter(out), new PrintWriter(System.err), program);
}
@Override
public void usage() {
println(i18n.getString("jdis.usage"));