Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6334127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:35:59+00:00 2026-05-24T18:35:59+00:00

Let’s say I have this Java app: package com.site; public class MyAppBase {} package

  • 0

Let’s say I have this Java app:

package com.site;

public class MyAppBase {}

package com.site.free;

import com.site.MyAppBase;

public class MyApp extends MyAppBase {}

package com.site.pro;

import com.site.MyAppBase;

public class MyApp extends MyAppBase {}

package com.site;

public class Edition
{

    public static final int     FREE    = 1;
    public static final int     PRO     = 2;

    private static final int    EDITION = PRO;

    public static boolean is(final int edition)
    {
        return (EDITION == edition);
    }
}

package com.site;

public class EditionFactory
{

    public static MyAppBase get_app()
    {
        MyAppBase ret = null;

        if (Edition.is(Edition.FREE))
            ret = new com.site.free.MyApp();
        else if (Edition.is(Edition.PRO))
            ret = new com.site.pro.MyApp();

        return ret;
    }
}

Now, any combination of ProGuard configuration I’m trying to get rid of the non-selected edition (in this case it’s FREE) doesn’t work.

By “getting rid of” I mean make the actual class disappear (as well from the calling code).

In other words, a call like this:

final MyAppBase app = EditionFactory.get_app();

.. is currently being translated to, after ProGuarding it, this:

if (a.a(1))
    localObject5 = new c(); // <<< FREE
else if (a.a(2))
    localObject5 = new d(); // <<< PRO

.. while I’d wish it to be translated to this:

localObject5 = new d(); // <<< PRO only in the code (as set at Edition.EDITION)

Bottom line is (besides the fact that ProGuard is GREAT!!), I can’t seem to make it “see through” and understand that Edition.is() is a boolean function returning a constant which makes it ok to remove some classes.

I’ve tried configurations like:

-keep,allowshrinking,allowoptimization public class * extends com.site.MyAppBase
-optimizationpasses 10

.. nothing works.

On the other hand, if I refer to Edition.EDITION and comparing it inlined (i.e without any “proxy” functions), the Java compiler (v1.6) detects it and remove the whole reference to the non-selected edition/class.
This results in that ProGuard removes/shrinks the unused class which is great.

The only issue here is about maintaining – I’d be happy to keep being able to use the EditionFactory style.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T18:36:00+00:00Added an answer on May 24, 2026 at 6:36 pm

    The optimization isn’t performed because ProGuard decides not to inline the method Edition#is, so it then can’t simplify the resulting series of instructions. The method is not inlined because it is not very short and it is also invoked more than once. You could work around the first criterion with this undocumented JVM option for ProGuard:

    -Dmaximum.inlined.code.length=16
    

    Alternatively, you could work around the second criterion, by making sure the method is only invoked once:

    return Edition.is(Edition.FREE) ?
        new com.site.free.MyApp() :
        new com.site.pro.MyApp();
    

    Alternatively, you could probably create short functions isFree() and isPro(), because they would return constants, which would be inlined.

    It’s a good practice to check the processed code if you’re expecting some particular optimizations, because they are often subject to complex constraints.

    Nice to hear that you like ProGuard.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a class like this: public class Person { private String
Let's say I have this: public DefaultListModel model = new DefaultListModel(); how do i
Let's say you have a class called Customer, which contains the following fields: UserName
Let's say I have this: SolutionSet(const SolutionSet &solutionSet) { this->capacity_ = solutionSet.capacity_; this->solutionsList_ =
Let's say I have saved this kind of data (some text '.date(d).' some text)
Let's say I have this: float i = 1.5 in binary, this float is
Let's say I have a link in a table like: <td class=ms-vb width=100%> <a
Let's say I have a table that looks something like this: ------------------------------- id|column2|column3 |column4
Let us assume I have two classes: class Base{}; class Derived: public Base{}; none
Let's say I have 4 activities in my app: A (main activity) B C

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.