Skip to content
Permalink
Browse files
8253511: [lworld] ClassFileParser does not handle field type mismatch
Reviewed-by: hseigel
  • Loading branch information
fparain committed Sep 23, 2020
1 parent 9fc3d54 commit 4a26a176d3b9344f9d553ea0a4d009d687380bc4
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 1 deletion.
@@ -6596,7 +6596,14 @@ void ClassFileParser::post_process_parsed_stream(const ClassFileStream* const st
Handle(THREAD, _loader_data->class_loader()),
_protection_domain, true, CHECK);
assert(klass != NULL, "Sanity check");
assert(klass->access_flags().is_inline_type(), "Inline type expected");
if (!klass->access_flags().is_inline_type()) {
assert(klass->is_instance_klass(), "Sanity check");
ResourceMark rm(THREAD);
THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(),
err_msg("Class %s expects class %s to be an inline type, but it is not",
_class_name->as_C_string(),
InstanceKlass::cast(klass)->external_name()));
}
}
}

@@ -0,0 +1,54 @@
/*
* Copyright (c) 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package compiler.valhalla.inlinetypes;

import jdk.test.lib.Asserts;

/**
* @test
* @library /test/lib
* @compile TestFieldTypeMismatchHelper.jasm
* @compile TestFieldTypeMismatch.java
* @run main/othervm compiler.valhalla.inlinetypes.TestFieldTypeMismatch
*/

final class MyValue {
int foo = 42;
}

public class TestFieldTypeMismatch {

public static void main(String[] args) {
boolean exception = false;
try {
TestFieldTypeMismatchHelper t = new TestFieldTypeMismatchHelper();
} catch(IncompatibleClassChangeError err) {
exception = true;
Asserts.assertEquals(err.getMessage(),
"Class compiler/valhalla/inlinetypes/TestFieldTypeMismatchHelper expects class compiler.valhalla.inlinetypes.MyValue to be an inline type, but it is not");
}
Asserts.assertTrue(exception);
}
}

@@ -0,0 +1,44 @@
/*
* Copyright (c) 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/

public class compiler/valhalla/inlinetypes/TestFieldTypeMismatchHelper version 60:0 {

Field field:"Qcompiler/valhalla/inlinetypes/MyValue;";

public Method "<init>":"()V"
stack 1 locals 1
{
aload_0;
invokespecial Method java/lang/Object."<init>":"()V";
return;
}

public Method test:"()V" stack 2 locals 1 {
aload_0;
aconst_null;
putfield Field field:"Qcompiler/valhalla/inlinetypes/MyValue;";
return;
}
}

0 comments on commit 4a26a17

Please sign in to comment.