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 6580439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:01:47+00:00 2026-05-25T16:01:47+00:00

I’m currently working on a Java project where it’s part of my job to

  • 0

I’m currently working on a Java project where it’s part of my job to watch over the quality. As tools I use Jenkins in combination with Sonar. These tools are great and the helped me to track issues fast and continuously.

One issue I don’t get under control is that some people commit using other encoding than UTF-8.

When code like this:

if (someString == "something") {
    resultString = "string with encoding problem: �";
}

… gets committed, Sonar will help me finding the “String Literal Equality” issue. But as you see in the second line there is an issue with the encoding: “�” should usually be an “ü“.

Is there any possibility to find these kinds of problems with Sonar/Findbugs/PMD…

Please advice!
Thank you.

Ps: Of course I’ve tried to explain the issue to my co-developers in person as well as via email. I even changed their project/workspace encoding myself… But somehow the still succeed in committing code like this.

  • 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-25T16:01:47+00:00Added an answer on May 25, 2026 at 4:01 pm

    I’m agree with @bmargulies, it’s a valid UTF-8 char (actually it’s the replacement character) but after all, a PMD rule could help. Here is a proof of concept rule with a hard-coded unallowed character list:

    import net.sourceforge.pmd.AbstractJavaRule;
    import net.sourceforge.pmd.ast.ASTLiteral;
    
    import org.apache.commons.lang3.StringUtils;
    
    public class EncodingRule extends AbstractJavaRule {
    
        private static final String badChars = "\uFFFD";
    
        public EncodingRule() {
        }
    
        @Override
        public Object visit(final ASTLiteral node, final Object data) {
            if (node.isStringLiteral()) {
                final String image = node.getImage();
                if (StringUtils.containsAny(image, badChars)) {
                    addViolationWithMessage(data, node, "Disallowed char in '"
                            + image + "'");
                }
            }
            return super.visit(node, data);
        }
    
    }
    

    Maybe it would be useful to invert the condition and make an allowedChars whitelist with ASCII characters and your local chars as well. (There is some more detail of custom PMD rules in this answer.)

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

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
I have thousands of HTML files to process using Groovy/Java and I need to
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.