/*
 *  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 java.beans;

import com.google.j2objc.LibraryNotLinkedError;

public class BeansFactory {

  public static PropertyChangeSupport newPropertyChangeSupportSafe(Object sourceBean) {
    FactoryInterface impl = IMPL;
    if (impl != null) {
      return impl.newPropertyChangeSupport(sourceBean);
    } else {
      return null;
    }
  }

  public static void throwNotLoadedError() {
    throw new LibraryNotLinkedError("java.beans support", "jre_beans",
        "JavaBeansPropertyChangeSupport");
  }

  private static final FactoryInterface IMPL = findImplementation();

  private static FactoryInterface findImplementation() {
    try {
      return (FactoryInterface) Class.forName("java.beans.BeansFactoryImpl").newInstance();
    } catch (Exception e) {
      return null;
    }
  }

  interface FactoryInterface {

    public PropertyChangeSupport newPropertyChangeSupport(Object sourceBean);
  }
}

@@ -1385,16 +1385,100 @@
 ion();%0A%0A
+  // Uses a native implementation to avoid the exception thrown by Class.forName().%0A
   privat
@@ -1486,16 +1486,23 @@
  static 
+native 
 FactoryI
@@ -1535,78 +1535,53 @@
 n() 
-%7B%0A    try %7B%0A      return (FactoryInterface) Class.forName(%22java.b
+/*-%5B%0A    Class cls = objc_getClass(%22JavaB
 eans
-.
 Bean
@@ -1598,49 +1598,82 @@
 pl%22)
-.newInstance();%0A    %7D catch (Exception e)
+;%0A    if (cls) %7B%0A      return %5B%5B%5Bcls alloc%5D init%5D autorelease%5D;%0A    %7D else
  %7B%0A 
@@ -1677,34 +1677,33 @@
 %7B%0A      return n
-ul
+i
 l;%0A    %7D%0A  %7D%0A%0A  
@@ -1693,25 +1693,29 @@
 il;%0A    %7D%0A  
-%7D
+%5D-*/;
 %0A%0A  interfac

Use native code to lookup the BeansFactoryImpl to avoid an exception being thrown which will trigger a breakpoint when debugging. Change on 2016/02/04 by kstanger <kstanger@google.com> ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=113850493