Start working on FELIX-2472 [iPOJO] Proxies should throw the OSGi service exception
Adapt the dependency handler to throw a runtime exception when there is no services in proxy mode with disabled nullables.
Also fix a bunch of typo.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@963398 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
index 6b6637d..159182d 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
@@ -256,7 +256,7 @@
             String type = meta.getFieldType();
             if (type.endsWith("[]")) {
                 if (dep.isProxy()) {
-                    info("Arrays cannot be used for proxied dependencies - Disable the proxy mode");
+                    info("Arrays cannot be used for proxied dependencies - Disabling the proxy mode");
                     dep.setProxy(false);
                 }
                 // Set the dependency to multiple
@@ -268,7 +268,7 @@
             } else if (type.equals(Vector.class.getName())) {
                 dep.setType(VECTOR);
                 if (dep.isProxy()) {
-                    warn("Vectors cannot be used for proxied dependencies - Disable the proxy mode");
+                    warn("Vectors cannot be used for proxied dependencies - Disabling the proxy mode");
                     dep.setProxy(false);
                 }
                 type = null;
@@ -286,10 +286,10 @@
         }
         
         // Disables proxy on null (nullable=false)
-        if (dep.isProxy()  && dep.isOptional() && ! dep.supportsNullable()) {
-            dep.setProxy(false);
-            warn("Optional Null Dependencies do not support proxying - Disable the proxy mode");
-        }
+//        if (dep.isProxy()  && dep.isOptional() && ! dep.supportsNullable()) {
+//            dep.setProxy(false);
+//            warn("Optional Null Dependencies do not support proxying - Disable the proxy mode");
+//        }
 
         // Check that all required info are set
         return dep.getSpecification() != null;
@@ -403,7 +403,7 @@
                     isProxy = false;
                 } else if (proxy.equals("true")) {
                     if (! isProxy) { // The configuration overrides the system setting
-                        warn("The configuration of a service dependency overides the proxy mode");
+                        warn("The configuration of a service dependency overrides the proxy mode");
                     }
                     isProxy = true;
                 }   
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ProxyGenerator.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ProxyGenerator.java
index 65c20e1..a7d965d 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ProxyGenerator.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/ProxyGenerator.java
@@ -23,6 +23,7 @@
 import java.lang.reflect.Modifier;
 
 import org.objectweb.asm.ClassWriter;
+import org.objectweb.asm.Label;
 import org.objectweb.asm.MethodVisitor;
 import org.objectweb.asm.Opcodes;
 import org.objectweb.asm.Type;
@@ -124,6 +125,22 @@
         freeRoom = freeRoom + 1; // Object Reference.
         mv.visitVarInsn(ASTORE, varSvc); // Store the service object.
         
+        Label notNull = new Label();
+        Label isNull = new Label();
+        mv.visitVarInsn(ALOAD, varSvc); // Load the service
+        mv.visitJumpInsn(IFNONNULL, notNull); // If not null go to not null
+        // Null branch - throw the exception
+        mv.visitLabel(isNull);
+        mv.visitTypeInsn(NEW, "java/lang/RuntimeException");
+        mv.visitInsn(DUP);
+        mv.visitLdcInsn("No service available");
+        mv.visitMethodInsn(INVOKESPECIAL, "java/lang/RuntimeException", "<init>", "(Ljava/lang/String;)V");
+        mv.visitInsn(ATHROW);
+        // End of the null branch
+        
+        // Not null, go one the execution
+        mv.visitLabel(notNull);
+                
         // Invoke the method on the service object.
         mv.visitVarInsn(ALOAD, varSvc);
         // Push argument on the stack.