Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Problem compiling StringUtils.class

  1. #1
    Junior Member
    Join Date
    Dec 2022
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problem compiling StringUtils.class

    Hi, I have decompile and recompile a jar file to modify the class StringUtils.class. Once I modified it and recompile is giving me problems during run.
    When I compare the original function list to that I have recompile, there is a public function that is not present in the original. I am using "javac -cp guevana-20.0.jar StringUtils.java" to compile.

    The javap results are the following:

    //original
    public final class com.google.appinventor.common.utils.StringUtils {
    public static final com.google.common.base.CharMatcher VALID_FILENAME_CHARS;
    public static java.lang.String quote(java.lang.String);
    public static java.lang.String unquote(java.lang.String);
    public static java.lang.String escape(java.lang.String);
    public static boolean contains(java.lang.String[], java.lang.String);
    public static java.lang.String join(java.lang.String, java.lang.String[]);
    public static java.lang.String join(java.lang.String, java.lang.Iterable<java.lang.String>);
    public static void join(java.lang.StringBuilder, java.lang.String, java.lang.String...);
    public static java.lang.String userToPackageName(java.lang.String);
    public static java.lang.String getProjectPackage(java.lang.String, java.lang.String);
    public static java.lang.String getQualifiedFormName(java.lang.String, java.lang.String);
    public static java.lang.String replaceLastOccurrence(java.lang.String, java.lang.String, java.lang.String);
    public static java.lang.String createProjectName(java.util.Set<java.lang.String>) ;
    public static java.lang.String normalizeForFilename(java.lang.String);
    public static java.lang.String toJson(java.lang.String);
    public static int countMatches(java.lang.String, java.lang.String);
    public static boolean isNullOrEmpty(java.lang.String);
    static {};
    }

    //my compilation

    public final class com.google.appinventor.common.utils.StringUtils {
    public static final com.google.common.base.CharMatcher VALID_FILENAME_CHARS;
    public com.google.appinventor.common.utils.StringUtils();
    public static java.lang.String quote(java.lang.String);
    public static java.lang.String unquote(java.lang.String);
    public static java.lang.String escape(java.lang.String);
    public static boolean contains(java.lang.String[], java.lang.String);
    public static java.lang.String join(java.lang.String, java.lang.String[]);
    public static java.lang.String join(java.lang.String, java.lang.Iterable<java.lang.String>);
    public static void join(java.lang.StringBuilder, java.lang.String, java.lang.String...);
    public static java.lang.String userToPackageName(java.lang.String);
    public static java.lang.String getProjectPackage(java.lang.String, java.lang.String);
    public static java.lang.String getQualifiedFormName(java.lang.String, java.lang.String);
    public static java.lang.String replaceLastOccurrence(java.lang.String, java.lang.String, java.lang.String);
    public static java.lang.String createProjectName(java.util.Set<java.lang.String>) ;
    public static java.lang.String normalizeForFilename(java.lang.String);
    public static java.lang.String toJson(java.lang.String);
    public static int countMatches(java.lang.String, java.lang.String);
    public static boolean isNullOrEmpty(java.lang.String);
    static {};
    }

    public final class com.google.appinventor.common.utils.StringUtils {
    public static final com.google.common.base.CharMatcher VALID_FILENAME_CHARS;
    public com.google.appinventor.common.utils.StringUtils();
    public static java.lang.String quote(java.lang.String);
    public static java.lang.String unquote(java.lang.String);
    public static java.lang.String escape(java.lang.String);
    public static boolean contains(java.lang.String[], java.lang.String);
    public static java.lang.String join(java.lang.String, java.lang.String[]);
    public static java.lang.String join(java.lang.String, java.lang.Iterable<java.lang.String>);
    public static void join(java.lang.StringBuilder, java.lang.String, java.lang.String...);
    public static java.lang.String userToPackageName(java.lang.String);
    public static java.lang.String getProjectPackage(java.lang.String, java.lang.String);
    public static java.lang.String getQualifiedFormName(java.lang.String, java.lang.String);
    public static java.lang.String replaceLastOccurrence(java.lang.String, java.lang.String, java.lang.String);
    public static java.lang.String createProjectName(java.util.Set<java.lang.String>) ;
    public static java.lang.String normalizeForFilename(java.lang.String);
    public static java.lang.String toJson(java.lang.String);
    public static int countMatches(java.lang.String, java.lang.String);
    public static boolean isNullOrEmpty(java.lang.String);
    static {};
    }



    Question:
    How can I get rid of the "public com.google.appinventor.common.utils.StringUtils(); " public function that appears on my compiled file?

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Problem compiling StringUtils.class

    giving me problems during run.
    Sorry, I do not understand what the problem is when the code is executed.
    Can you copy the full text of the error messages from when the code is executed?

    public com.google.appinventor.common.utils.StringUtils();
    Looks like a constructor for the class
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2022
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problem compiling StringUtils.class

    Quote Originally Posted by Norm View Post
    Sorry, I do not understand what the problem is when the code is executed.
    Can you copy the full text of the error messages from when the code is executed?


    Looks like a constructor for the class
    This is the error message once the whole program is run. The StringUtils.class is in the package com.google.appinventor.common.utils, in a file called CommonUtils.jar.
    I can not figure out why the original CommonUtils,jar works, and my compilation does not.

    Dec 27, 2022 10:51:07 PM com.google.appinventor.buildserver.BuildServer$1 run
    INFO: BUILD 1 FINISHED
    Exception in thread "Thread-3" java.lang.NoClassDefFoundError: com/google/appinventor/common/utils/StringUtils
    at com.google.appinventor.buildserver.ProjectBuilder. processCompilerOutput(ProjectBuilder.java:463)
    at com.google.appinventor.buildserver.ProjectBuilder. build(ProjectBuilder.java:184)
    at com.google.appinventor.buildserver.BuildServer.bui ld(BuildServer.java:734)
    at com.google.appinventor.buildserver.BuildServer.bui ldAndCreateZip(BuildServer.java:689)
    at com.google.appinventor.buildserver.BuildServer.acc ess$300(BuildServer.java:74)
    at com.google.appinventor.buildserver.BuildServer$1.r un(BuildServer.java:625)
    at com.google.appinventor.buildserver.NonQueuingExecu tor$1.run(NonQueuingExecutor.java:52)
    at java.lang.Thread.run(Thread.java:750)
    Caused by: java.lang.ClassNotFoundException: com.google.appinventor.common.utils.StringUtils
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:387)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:4 18)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:352)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 51)
    ... 8 more

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Problem compiling StringUtils.class

    Look in your jar file to see what it contains. You can use any zip utility program to open it. Rename to .zip if needed.
    See if the StringUtils.class file is on the path: com/google/appinventor/common/utils/
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Dec 2022
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problem compiling StringUtils.class

    Quote Originally Posted by Norm View Post
    Look in your jar file to see what it contains. You can use any zip utility program to open it. Rename to .zip if needed.
    See if the StringUtils.class file is on the path: com/google/appinventor/common/utils/
    Thanks for your answer. I do that already. I think I did not provide sufficient information.
    There is a whole suite called app inventor. Inside the suite, there is one JAR file called CommonUtils.jar.
    When I unzip it, there is three CLASS files. One of those three CLASS files is StringUtils.class.
    I decompile it from StringUtils.class to STringUtils.java. I then modify one constant and recompile and repackage into a new JAR.
    Once I run it, I get an error message. In theory, I should not get any error since I am just modifying a String constant, and no method is added nor modified.

    When trying to figure out why I get the error message, I noticed that there is a single difference in the
    methods from the original compared to the one I compiled, and that difference is an extra method in my compilation that has the same name as the CLASS.
    The original jar and classes were compiled with Ant and the one I am compiling is with javac.

    Does anybody know any possible cause for this problem, such as:
    1. Using javac vs Ant for compilation.
    2. Am I missing any argument when compiling to remove the main class (to build a library for example)?
    3. Version incompatibility?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Problem compiling StringUtils.class

    repackage into a new JAR.
    What is in the jar file? Is the .class file on the correct path? The class file won't be found if it is on the wrong path.

    Have you tried writing a small, simple program that uses one or more of the methods in that class to see if the jar file will work without any other things involved in the test?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Problem with Compiling on mac
    By Scorks in forum Java Theory & Questions
    Replies: 6
    Last Post: September 5th, 2013, 05:47 PM
  2. problem with compiling
    By silverpen10 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 21st, 2013, 02:08 PM
  3. .class compiling error
    By nijininjin in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 26th, 2012, 03:01 PM
  4. [SOLVED] Insurance Premium class not compiling
    By mwardjava92 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 3rd, 2011, 03:27 PM
  5. Need help compiling java class files
    By peahead in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 11th, 2010, 09:04 AM

Tags for this Thread