commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject svn commit: r1589418 - in /commons/proper/bcel/trunk/src: main/java/org/apache/bcel/verifier/statics/Pass2Verifier.java test/java/org/apache/bcel/verifier/ test/java/org/apache/bcel/verifier/VerifierTestCase.java
Date Wed, 23 Apr 2014 14:05:41 GMT
Author: ebourg
Date: Wed Apr 23 14:05:41 2014
New Revision: 1589418

URL: http://svn.apache.org/r1589418
Log:
Fixed the verification of Java 8 interfaces (BCEL-174)

Added:
    commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/
    commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/VerifierTestCase.java
  (with props)
Modified:
    commons/proper/bcel/trunk/src/main/java/org/apache/bcel/verifier/statics/Pass2Verifier.java

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/verifier/statics/Pass2Verifier.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/verifier/statics/Pass2Verifier.java?rev=1589418&r1=1589417&r2=1589418&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/verifier/statics/Pass2Verifier.java
(original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/verifier/statics/Pass2Verifier.java
Wed Apr 23 14:05:41 2014
@@ -682,22 +682,35 @@ public final class Pass2Verifier extends
 			}
 			else{ // isInterface!
 				if (!name.equals(STATIC_INITIALIZER_NAME)){//vmspec2, p.116, 2nd paragraph
-					if (!obj.isPublic()){
-						throw new ClassConstraintException("Interface method '"+tostring(obj)+"' must have
the ACC_PUBLIC modifier set but hasn't!");
-					}
-					if (!obj.isAbstract()){
-						throw new ClassConstraintException("Interface method '"+tostring(obj)+"' must have
the ACC_ABSTRACT modifier set but hasn't!");
-					}
-					if (	obj.isPrivate() ||
-								obj.isProtected() ||
-								obj.isStatic() ||
-								obj.isFinal() ||
-								obj.isSynchronized() ||
-								obj.isNative() ||
-								obj.isStrictfp() ){
-						throw new ClassConstraintException("Interface method '"+tostring(obj)+"' must not have
any of the ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, ACC_SYNCHRONIZED, ACC_NATIVE,
ACC_ABSTRACT, ACC_STRICT modifiers set.");
-					}
-				}
+                    if (jc.getMajor() >= MAJOR_1_8) {
+                        if (!(obj.isPublic() ^ obj.isPrivate())) {
+                            throw new ClassConstraintException("Interface method '" + tostring(obj)
+ "' must have exactly one of its ACC_PUBLIC and ACC_PRIVATE modifiers set.");
+                        }
+                        if (obj.isProtected()
+                                || obj.isFinal()
+                                || obj.isSynchronized()
+                                || obj.isNative()) {
+                            throw new ClassConstraintException("Interface method '"+tostring(obj)+"'
must not have any of the ACC_PROTECTED, ACC_FINAL, ACC_SYNCHRONIZED, or ACC_NATIVE modifiers
set.");
+                        }
+
+                    } else {
+                        if (!obj.isPublic()){
+                            throw new ClassConstraintException("Interface method '"+tostring(obj)+"'
must have the ACC_PUBLIC modifier set but hasn't!");
+                        }
+                        if (!obj.isAbstract()){
+                            throw new ClassConstraintException("Interface method '"+tostring(obj)+"'
must have the ACC_ABSTRACT modifier set but hasn't!");
+                        }
+                        if (obj.isPrivate()
+                                || obj.isProtected()
+                                || obj.isStatic()
+                                || obj.isFinal()
+                                || obj.isSynchronized()
+                                || obj.isNative()
+                                || obj.isStrictfp() ) {
+                            throw new ClassConstraintException("Interface method '"+tostring(obj)+"'
must not have any of the ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, ACC_SYNCHRONIZED,
ACC_NATIVE, ACC_ABSTRACT, ACC_STRICT modifiers set.");
+                        }
+                    }
+                }
 			}
 
 			// A specific instance initialization method... (vmspec2,Page 116).

Added: commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/VerifierTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/VerifierTestCase.java?rev=1589418&view=auto
==============================================================================
--- commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/VerifierTestCase.java
(added)
+++ commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/VerifierTestCase.java
Wed Apr 23 14:05:41 2014
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ */
+
+package org.apache.bcel.verifier;
+
+import java.util.Collection;
+
+import junit.framework.TestCase;
+
+public class VerifierTestCase extends TestCase {
+
+    public void testDefaultMethodValidation() {
+        String classname = Collection.class.getName();
+        
+        Verifier verifier = VerifierFactory.getVerifier(classname);
+        VerificationResult result = verifier.doPass1();
+
+        assertEquals("Pass 1 verification of " + classname + " failed: " + result.getMessage(),
VerificationResult.VERIFIED_OK, result.getStatus());
+        
+        result = verifier.doPass2();
+        
+        assertEquals("Pass 2 verification of " + classname + " failed: " + result.getMessage(),
VerificationResult.VERIFIED_OK, result.getStatus());
+    }
+}

Propchange: commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/VerifierTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/bcel/trunk/src/test/java/org/apache/bcel/verifier/VerifierTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL



Mime
View raw message