src/share/vm/classfile/verifier.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File bug_8064335 Sdiff src/share/vm/classfile

src/share/vm/classfile/verifier.cpp

Print this page




2460     }
2461     u2 new_class_index = Bytes::get_Java_u2(new_bcp + 1);
2462     verify_cp_class_type(bci, new_class_index, cp, CHECK_VERIFY(this));
2463 
2464     // The method must be an <init> method of the indicated class
2465     VerificationType new_class_type = cp_index_to_type(
2466       new_class_index, cp, CHECK_VERIFY(this));
2467     if (!new_class_type.equals(ref_class_type)) {
2468       verify_error(ErrorContext::bad_type(bci,
2469           TypeOrigin::cp(new_class_index, new_class_type),
2470           TypeOrigin::cp(ref_class_index, ref_class_type)),
2471           "Call to wrong <init> method");
2472       return;
2473     }
2474     // According to the VM spec, if the referent class is a superclass of the
2475     // current class, and is in a different runtime package, and the method is
2476     // protected, then the objectref must be the current class or a subclass
2477     // of the current class.
2478     VerificationType objectref_type = new_class_type;
2479     if (name_in_supers(ref_class_type.name(), current_class())) {
2480       Klass* ref_klass = load_class(
2481         ref_class_type.name(), CHECK_VERIFY(this));
2482       Method* m = InstanceKlass::cast(ref_klass)->uncached_lookup_method(
2483         vmSymbols::object_initializer_name(),
2484         cp->signature_ref_at(bcs->get_index_u2()),
2485         Klass::normal);
2486       // Do nothing if method is not found.  Let resolution detect the error.
2487       if (m != NULL) {
2488         instanceKlassHandle mh(THREAD, m->method_holder());
2489         if (m->is_protected() && !mh->is_same_class_package(_klass())) {
2490           bool assignable = current_type().is_assignable_from(
2491             objectref_type, this, true, CHECK_VERIFY(this));
2492           if (!assignable) {
2493             verify_error(ErrorContext::bad_type(bci,
2494                 TypeOrigin::cp(new_class_index, objectref_type),
2495                 TypeOrigin::implicit(current_type())),
2496                 "Bad access to protected <init> method");
2497             return;
2498           }
2499         }
2500       }
2501     }




2460     }
2461     u2 new_class_index = Bytes::get_Java_u2(new_bcp + 1);
2462     verify_cp_class_type(bci, new_class_index, cp, CHECK_VERIFY(this));
2463 
2464     // The method must be an <init> method of the indicated class
2465     VerificationType new_class_type = cp_index_to_type(
2466       new_class_index, cp, CHECK_VERIFY(this));
2467     if (!new_class_type.equals(ref_class_type)) {
2468       verify_error(ErrorContext::bad_type(bci,
2469           TypeOrigin::cp(new_class_index, new_class_type),
2470           TypeOrigin::cp(ref_class_index, ref_class_type)),
2471           "Call to wrong <init> method");
2472       return;
2473     }
2474     // According to the VM spec, if the referent class is a superclass of the
2475     // current class, and is in a different runtime package, and the method is
2476     // protected, then the objectref must be the current class or a subclass
2477     // of the current class.
2478     VerificationType objectref_type = new_class_type;
2479     if (name_in_supers(ref_class_type.name(), current_class())) {
2480       Klass* ref_klass = load_class(ref_class_type.name(), CHECK);

2481       Method* m = InstanceKlass::cast(ref_klass)->uncached_lookup_method(
2482         vmSymbols::object_initializer_name(),
2483         cp->signature_ref_at(bcs->get_index_u2()),
2484         Klass::normal);
2485       // Do nothing if method is not found.  Let resolution detect the error.
2486       if (m != NULL) {
2487         instanceKlassHandle mh(THREAD, m->method_holder());
2488         if (m->is_protected() && !mh->is_same_class_package(_klass())) {
2489           bool assignable = current_type().is_assignable_from(
2490             objectref_type, this, true, CHECK_VERIFY(this));
2491           if (!assignable) {
2492             verify_error(ErrorContext::bad_type(bci,
2493                 TypeOrigin::cp(new_class_index, objectref_type),
2494                 TypeOrigin::implicit(current_type())),
2495                 "Bad access to protected <init> method");
2496             return;
2497           }
2498         }
2499       }
2500     }


src/share/vm/classfile/verifier.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File