From duke at openjdk.org Tue Jun 25 21:28:23 2024 From: duke at openjdk.org (duke) Date: Tue, 25 Jun 2024 21:28:23 GMT Subject: Withdrawn: Add utility for creating objects via factory method when unable to create via constructor In-Reply-To: References: Message-ID: On Thu, 7 Mar 2024 17:27:38 GMT, Kyle J Stiemann wrote: > Adds CLI option to provide a factory FQCN which can create objects that you want to analyze. This is useful in situations where you have dependency classes or JDK classes that require non-null objects or have other validation in the constructor. These kinds of classes can't easily be modified, so it's nice to provide an alternative option for creating them. > > For example: > > > public static final class RequiresFactory { > public RequiresFactory(final String string) { > Objects.requireNonNull(string); > if (string.isEmpty()) { > throw new IllegalArgumentException("string must not be empty"); > } > } > } > > > Usage: > > > java -jar jol-cli.jar internals --classpath my-classes.jar --factory my.Factory my.RequiresFactory > > > Where `my.Factory` is: > > > public class Factory { > public static T newInstance(Class aClass) { > > if (aClass.equals(RequiresFactory.class)) { > return aClass.cast(new RequiresFactory("test")); > } > > throw new UnsupportedOperationException(aClass.getTypeName()); > } > } This pull request has been closed without being integrated. ------------- PR: https://git.openjdk.org/jol/pull/58