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

  • SEARCH
  • Home
  • 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 8093295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:28:30+00:00 2026-06-05T20:28:30+00:00

I would like to do some static code analysis for Java source code. For

  • 0

I would like to do some static code analysis for Java source code. For parsing I use the Eclipse JDT (3.6) ASTParser outside of Eclipse with following code:

private static final Map<String, String> COMPILER_OPTIONS;

static {
    COMPILER_OPTIONS = new HashMap<String, String>(JavaCore.getOptions());
    COMPILER_OPTIONS.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_6);
    COMPILER_OPTIONS.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_6);
    COMPILER_OPTIONS.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_6);
}

private CompilationUnit parseReadSourceFileIfPossible(String readSourceFile) {
    CompilationUnit result = null;
    if (isPossibleToParse(readSourceFile)) {
        final ASTParser parser = createAndConfigureParser();
        parser.setSource(readSourceFile.toCharArray());
        result = (CompilationUnit) parser.createAST(null);
    }
    return result;
}

private ASTParser createAndConfigureParser() {
    final ASTParser result = ASTParser.newParser(AST.JLS3);
    result.setKind(ASTParser.K_COMPILATION_UNIT);
    result.setCompilerOptions(COMPILER_OPTIONS); return result;
}

For “normal” Java classes this approach works perfectly fine. However if I
parse the following class (ValidUnrestrictedComponent), the parser runs
into problems.

package valid;

import de.htwg_konstanz.joi.annotations.JoiComponten;

@JoiComponent
public final class ValidUnrestrictedComponent {

    private static final class Implementation implements TestInterface {

        @Override
        public int doSomething() {
            // TODO Auto-generated method stub
            return 0;
        }
    }

    private ValidUnrestrictedComponent() {
        throw new AssertionError();
    }

    public static Implementation getInstance() {
        return new Implementation();
    }

    private static void getNothing() {
      // Nothing to do here
    }

    private void doNothing() {
      // Nothing to do here
    }

}

I do receive an object of type CompilationUnit, however it does only contain the
nested member Implementation and its method. The rest of the class – like
getInstance or doNothing is missing.

The obtained CompilationUnit contains a field problems with the following
three problems:

  • DefaultProblem (id=141): Pb(240) Syntax error, insert “}” to complete ClassBody
  • DefaultProblem (id=143): Pb(240) Syntax error, insert “}” to complete ClassBody
  • DefaultProblem (id=164): Pb(240) Syntax error, insert “}” to complete MethodBody

I can not see any syntax errors in the above mentioned class
ValidUnrestrictedComponent.

  • 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-06-05T20:28:32+00:00Added an answer on June 5, 2026 at 8:28 pm

    Can you double check the contents of ‘readSourceFile’? My guess is that there are no ‘\n’ or new line characters in that. Missing new-line characters would result in all the lines after the first comment becoming part of the comment itself.

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

Sidebar

Related Questions

I would like to use Cppcheck for static code analysis of my C++ code.
I would like some advice on the best approach to use in the following
I would like to create some reverse egineered design docs based on Java code
I would like some help parsing a dynamic (folder.subfolders) xml with xslt, I tried
I would like to call some custom copy code when the user releases Ctrl
We would like to add some start code to indicate log file for every
I would like to add some C# debug only code that only runs if
I would like to get some help to sort out the code I've come
There's some legacy code that I would like to refactor. There is some data
I would like to reuse some existing code in our code base that accepts

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.