178c496fe0fac4c89993109340aec80d1afa3141fIan Parkinson/** 2eebfcaffb2d52b214abfdb1c0102395c88c9db54Paul Duffin * Copyright 2006-2017 the original author or authors. 378c496fe0fac4c89993109340aec80d1afa3141fIan Parkinson * 478c496fe0fac4c89993109340aec80d1afa3141fIan Parkinson * Licensed under the Apache License, Version 2.0 (the "License"); 578c496fe0fac4c89993109340aec80d1afa3141fIan Parkinson * you may not use this file except in compliance with the License. 678c496fe0fac4c89993109340aec80d1afa3141fIan Parkinson * You may obtain a copy of the License at 778c496fe0fac4c89993109340aec80d1afa3141fIan Parkinson * 878c496fe0fac4c89993109340aec80d1afa3141fIan Parkinson * http://www.apache.org/licenses/LICENSE-2.0 978c496fe0fac4c89993109340aec80d1afa3141fIan Parkinson * 1078c496fe0fac4c89993109340aec80d1afa3141fIan Parkinson * Unless required by applicable law or agreed to in writing, software 1178c496fe0fac4c89993109340aec80d1afa3141fIan Parkinson * distributed under the License is distributed on an "AS IS" BASIS, 1278c496fe0fac4c89993109340aec80d1afa3141fIan Parkinson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1378c496fe0fac4c89993109340aec80d1afa3141fIan Parkinson * See the License for the specific language governing permissions and 1478c496fe0fac4c89993109340aec80d1afa3141fIan Parkinson * limitations under the License. 1578c496fe0fac4c89993109340aec80d1afa3141fIan Parkinson */ 1678c496fe0fac4c89993109340aec80d1afa3141fIan Parkinsonpackage org.objenesis.instantiator.basic; 1778c496fe0fac4c89993109340aec80d1afa3141fIan Parkinson 18eebfcaffb2d52b214abfdb1c0102395c88c9db54Paul Duffinimport org.objenesis.instantiator.annotations.Instantiator; 19eebfcaffb2d52b214abfdb1c0102395c88c9db54Paul Duffinimport org.objenesis.instantiator.annotations.Typology; 20eebfcaffb2d52b214abfdb1c0102395c88c9db54Paul Duffin 2178c496fe0fac4c89993109340aec80d1afa3141fIan Parkinson/** 2278c496fe0fac4c89993109340aec80d1afa3141fIan Parkinson * Instantiates a class by grabbing the no-args constructor, making it accessible and then calling 2378c496fe0fac4c89993109340aec80d1afa3141fIan Parkinson * Constructor.newInstance(). Although this still requires no-arg constructors, it can call 2478c496fe0fac4c89993109340aec80d1afa3141fIan Parkinson * non-public constructors (if the security manager allows it). 25eebfcaffb2d52b214abfdb1c0102395c88c9db54Paul Duffin * 2678c496fe0fac4c89993109340aec80d1afa3141fIan Parkinson * @author Joe Walnes 2778c496fe0fac4c89993109340aec80d1afa3141fIan Parkinson * @see org.objenesis.instantiator.ObjectInstantiator 2878c496fe0fac4c89993109340aec80d1afa3141fIan Parkinson */ 29eebfcaffb2d52b214abfdb1c0102395c88c9db54Paul Duffin@Instantiator(Typology.NOT_COMPLIANT) 30eebfcaffb2d52b214abfdb1c0102395c88c9db54Paul Duffinpublic class AccessibleInstantiator<T> extends ConstructorInstantiator<T> { 3178c496fe0fac4c89993109340aec80d1afa3141fIan Parkinson 32eebfcaffb2d52b214abfdb1c0102395c88c9db54Paul Duffin public AccessibleInstantiator(Class<T> type) { 3378c496fe0fac4c89993109340aec80d1afa3141fIan Parkinson super(type); 3478c496fe0fac4c89993109340aec80d1afa3141fIan Parkinson if(constructor != null) { 3578c496fe0fac4c89993109340aec80d1afa3141fIan Parkinson constructor.setAccessible(true); 3678c496fe0fac4c89993109340aec80d1afa3141fIan Parkinson } 3778c496fe0fac4c89993109340aec80d1afa3141fIan Parkinson } 3878c496fe0fac4c89993109340aec80d1afa3141fIan Parkinson} 39