[ 
https://issues.apache.org/jira/browse/BCEL-193?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14275299#comment-14275299
 ] 

Jérôme Leroux commented on BCEL-193:
------------------------------------

I don't think so. If the classfile is compliant with the specification, the 
verifier must not reject it.
The {{ArrayStoreException}} is not an error ({{java.lang.Error}}) and is a 
normal exception that can be caught by the application such as a 
{{NullPointerException}} or a {{ClassCastException}}.

In §4.9 of _The Java Virtual Machine Specification Second Edition_ states:
{quote}
It _(the bytecode verifier)_ should certify all code generated by Sun's 
compiler for the Java programming language
{quote}

Here is the example defined in the {{ArrayStoreException}} javadoc:
{code:java}
Object x[] = new String[3];
x[0] = new Integer(0);
{code}
If this code should be rejected by the verifier, then the following code 
defined in {{ClassCastException}} should also:
{code:java}
Object x = new Integer(0);
System.out.println((String)x);
{code}

This kind of checks does not concern the verifier, they may be made by code 
analyzer such as PMD.

> aastore instruction should not raise a verify error if an assignment 
> compatiblity error is detected
> ---------------------------------------------------------------------------------------------------
>
>                 Key: BCEL-193
>                 URL: https://issues.apache.org/jira/browse/BCEL-193
>             Project: Commons BCEL
>          Issue Type: Bug
>          Components: Verifier
>    Affects Versions: 6.0
>            Reporter: Jérôme Leroux
>         Attachments: BCEL-193.patch, BCEL-193.zip
>
>
> The following valid code raises a verify error:
> {code:java}
> public class TestArrayAccess01 extends XTestArray01{
>     public static void test(){
>         XTestArray01[] array = new TestArrayAccess01[1];
>         array[0] = new XTestArray01();
>     }   
> }
> class XTestArray01 {}
> {code}
> The code above will throw an {{ArrayStoreException}} at runtime but the 
> generated bytecode is valid.
> _The Java Virtual Machine Specification Second Edition_ is ambigous about 
> this kind of issue. It states in §4.8.2 _Structural Constraints_ 
> (http://docs.oracle.com/javase/specs/jvms/se5.0/html/ClassFile.doc.html#9308):
> {quote}
> The type of every value stored into an array of type reference by an aastore 
> instruction must be assignment compatible (§2.6.7) with the component type of 
> the array.
> {quote}
> But in the {{aastore}} opcode description, there is no reference to any kind 
> of linking or verification error. The assignment compatiblity error is a 
> runtime exception.
> In the _Java SE 7 Edition_ of __The Java Virtual Machine Specification_, the 
> §4 has been modified 
> (http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.9.2):
> {quote}
> The type of every value stored into an array by an aastore instruction must 
> be a reference type.
> The component type of the array being stored into by the aastore instruction 
> must also be a reference type. 
> {quote}
> The assignment compatibility check must not be done during the verification 
> of the bytecode but during its execution.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to