zweb/src/main/java/org/zkoss/web/servlet/Servlets.java

Summary

Maintainability
F
1 wk
Test Coverage

File Servlets.java has 771 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* Servlets.java

    Purpose:
    Description:
    History:
Severity: Major
Found in zweb/src/main/java/org/zkoss/web/servlet/Servlets.java - About 1 day to fix

    Method browserInfo has a Cognitive Complexity of 79 (exceeds 5 allowed). Consider refactoring.
    Open

        private static void browserInfo(Map<String, Object> zk, String ua) {
            if (ua != null) {
                // ZK-1822: In locale Turkish, it can prevent 'I'.toLowerCase becomes 'i' without dot.
                ua = ua.toLowerCase(Locale.ENGLISH);
                if (_clientId != null) {
    Severity: Minor
    Found in zweb/src/main/java/org/zkoss/web/servlet/Servlets.java - About 1 day to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method getNormalPath has a Cognitive Complexity of 49 (exceeds 5 allowed). Consider refactoring.
    Open

        public static String getNormalPath(String path) {
            final StringBuffer sb = new StringBuffer(path);
            final IntStack slashes = new IntStack(32); //most 32 slash in a path
            slashes.push(-1);
            int j = 0, colon = -100, dot1 = -100, dot2 = -100;
    Severity: Minor
    Found in zweb/src/main/java/org/zkoss/web/servlet/Servlets.java - About 7 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Servlets has 45 methods (exceeds 20 allowed). Consider refactoring.
    Open

    public class Servlets {
        private static final Logger log = LoggerFactory.getLogger(Servlets.class);
    
        private static ClientIdentifier _clientId;
        private static final Pattern _rwebkit = Pattern.compile(".*(webkit)[ /]([\\w.]+).*"),
    Severity: Minor
    Found in zweb/src/main/java/org/zkoss/web/servlet/Servlets.java - About 6 hrs to fix

      Method locate has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
      Open

          @SuppressWarnings("unchecked")
          public static final String locate(ServletContext ctx, ServletRequest request, String pgpath, Locator locator)
                  throws ServletException {
              if (pgpath == null)
                  return pgpath;
      Severity: Minor
      Found in zweb/src/main/java/org/zkoss/web/servlet/Servlets.java - About 4 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method browserInfo has 78 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private static void browserInfo(Map<String, Object> zk, String ua) {
              if (ua != null) {
                  // ZK-1822: In locale Turkish, it can prevent 'I'.toLowerCase becomes 'i' without dot.
                  ua = ua.toLowerCase(Locale.ENGLISH);
                  if (_clientId != null) {
      Severity: Major
      Found in zweb/src/main/java/org/zkoss/web/servlet/Servlets.java - About 3 hrs to fix

        Method getNormalPath has 61 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static String getNormalPath(String path) {
                final StringBuffer sb = new StringBuffer(path);
                final IntStack slashes = new IntStack(32); //most 32 slash in a path
                slashes.push(-1);
                int j = 0, colon = -100, dot1 = -100, dot2 = -100;
        Severity: Major
        Found in zweb/src/main/java/org/zkoss/web/servlet/Servlets.java - About 2 hrs to fix

          Method browser has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
          Open

              private static boolean browser(String userAgent, String type) {
                  if (userAgent == null) //Bug ZK-1582: userAgent could be null if it is robot.
                      return false;
          
                  int last = (type = type.trim()).length();
          Severity: Minor
          Found in zweb/src/main/java/org/zkoss/web/servlet/Servlets.java - About 2 hrs to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Method locate has 58 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              @SuppressWarnings("unchecked")
              public static final String locate(ServletContext ctx, ServletRequest request, String pgpath, Locator locator)
                      throws ServletException {
                  if (pgpath == null)
                      return pgpath;
          Severity: Major
          Found in zweb/src/main/java/org/zkoss/web/servlet/Servlets.java - About 2 hrs to fix

            Method generateURI has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
            Open

                public static final String generateURI(String uri, Map params, int mode) {
                    if (uri.startsWith("~"))
                        throw new IllegalArgumentException("~ctx not supported here: " + uri);
            
                    final int j = uri.indexOf('?');
            Severity: Minor
            Found in zweb/src/main/java/org/zkoss/web/servlet/Servlets.java - About 1 hr to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Method getRequestDispatcher has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                public static final RequestDispatcher getRequestDispatcher(ServletContext ctx, ServletRequest request, String uri,
                        Map params, int mode) throws ServletException {
                    final char cc = uri.length() > 0 ? uri.charAt(0) : (char) 0;
                    if (ctx == null || (cc != '/' && cc != '~')) { //... or relevant
                        if (request == null)
            Severity: Minor
            Found in zweb/src/main/java/org/zkoss/web/servlet/Servlets.java - About 1 hr to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Method generateURI has 37 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public static final String generateURI(String uri, Map params, int mode) {
                    if (uri.startsWith("~"))
                        throw new IllegalArgumentException("~ctx not supported here: " + uri);
            
                    final int j = uri.indexOf('?');
            Severity: Minor
            Found in zweb/src/main/java/org/zkoss/web/servlet/Servlets.java - About 1 hr to fix

              Method forward has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
              Open

                  public static final void forward(ServletContext ctx, ServletRequest request, ServletResponse response, String uri,
                          Map params, int mode) throws IOException, ServletException {
                      //        if (log.isDebugEnabled()) log.debug("Forwarding "+uri);
              
                      //include or foward depending whether this page is included or not
              Severity: Minor
              Found in zweb/src/main/java/org/zkoss/web/servlet/Servlets.java - About 1 hr to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Method browser has 31 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  private static boolean browser(String userAgent, String type) {
                      if (userAgent == null) //Bug ZK-1582: userAgent could be null if it is robot.
                          return false;
              
                      int last = (type = type.trim()).length();
              Severity: Minor
              Found in zweb/src/main/java/org/zkoss/web/servlet/Servlets.java - About 1 hr to fix

                Method include has 6 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    public static final void include(ServletContext ctx, ServletRequest request, ServletResponse response, String uri,
                            Map params, int mode) throws IOException, ServletException {
                Severity: Minor
                Found in zweb/src/main/java/org/zkoss/web/servlet/Servlets.java - About 45 mins to fix

                  Method getExtension has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public static final String getExtension(String path, boolean lastOnly) {
                          if (lastOnly)
                              return getExtension(path);
                          if (path == null)
                              return null;
                  Severity: Minor
                  Found in zweb/src/main/java/org/zkoss/web/servlet/Servlets.java - About 45 mins to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Avoid deeply nested control flow statements.
                  Open

                                          if (slashes.isEmpty()) {
                                              slashes.push(-1);
                                          }
                  Severity: Major
                  Found in zweb/src/main/java/org/zkoss/web/servlet/Servlets.java - About 45 mins to fix

                    Method forward has 6 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        public static final void forward(ServletContext ctx, ServletRequest request, ServletResponse response, String uri,
                                Map params, int mode) throws IOException, ServletException {
                    Severity: Minor
                    Found in zweb/src/main/java/org/zkoss/web/servlet/Servlets.java - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                              if (preslash == 0) { //special case "/../"
                                                  throw new IllegalArgumentException("Illegal path: " + path);
                                              }
                      Severity: Major
                      Found in zweb/src/main/java/org/zkoss/web/servlet/Servlets.java - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                                if (j >= 0) {
                                                    int k = ua.indexOf('.', j += 8);
                                                    if (k >= 0) {
                                                        for (int len = ua.length(); ++k < len;) {
                                                            final char cc = ua.charAt(k);
                        Severity: Major
                        Found in zweb/src/main/java/org/zkoss/web/servlet/Servlets.java - About 45 mins to fix

                          Method getRequestDispatcher has 5 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                              public static final RequestDispatcher getRequestDispatcher(ServletContext ctx, ServletRequest request, String uri,
                                      Map params, int mode) throws ServletException {
                          Severity: Minor
                          Found in zweb/src/main/java/org/zkoss/web/servlet/Servlets.java - About 35 mins to fix

                            Method getResource has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                            Open

                                public static final URL getResource(ServletContext ctx, String uri) throws UnsupportedEncodingException {
                                    try {
                                        if (uri != null && uri.toLowerCase(java.util.Locale.ENGLISH).startsWith("file://")) {
                                            final File file = new File(new URI(uri));
                                            return file.exists() ? file.toURI().toURL() : null;
                            Severity: Minor
                            Found in zweb/src/main/java/org/zkoss/web/servlet/Servlets.java - About 35 mins to fix

                            Cognitive Complexity

                            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                            A method's cognitive complexity is based on a few simple rules:

                            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                            • Code is considered more complex for each "break in the linear flow of the code"
                            • Code is considered more complex when "flow breaking structures are nested"

                            Further reading

                            Method getResourceAsStream has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                            Open

                                public static final InputStream getResourceAsStream(ServletContext ctx, String uri) throws IOException {
                                    try {
                                        if (uri != null && uri.toLowerCase(java.util.Locale.ENGLISH).startsWith("file://")) {
                                            final File file = new File(new URI(uri));
                                            return file.exists() ? new BufferedInputStream(new FileInputStream(file)) : null;
                            Severity: Minor
                            Found in zweb/src/main/java/org/zkoss/web/servlet/Servlets.java - About 35 mins to fix

                            Cognitive Complexity

                            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                            A method's cognitive complexity is based on a few simple rules:

                            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                            • Code is considered more complex for each "break in the linear flow of the code"
                            • Code is considered more complex when "flow breaking structures are nested"

                            Further reading

                            Avoid too many return statements within this method.
                            Open

                                        return false; //not matched for Bug ZK-1930
                            Severity: Major
                            Found in zweb/src/main/java/org/zkoss/web/servlet/Servlets.java - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                      return qstr != null ? uri + qstr : uri;
                              Severity: Major
                              Found in zweb/src/main/java/org/zkoss/web/servlet/Servlets.java - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                        return equals ? v1 == v2 : v1 >= v2;
                                Severity: Major
                                Found in zweb/src/main/java/org/zkoss/web/servlet/Servlets.java - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                                      return;
                                  Severity: Major
                                  Found in zweb/src/main/java/org/zkoss/web/servlet/Servlets.java - About 30 mins to fix

                                    Method getUserAgent has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                    Open

                                        public static final String getUserAgent(ServletRequest req) {
                                            if (req instanceof HttpServletRequest) {
                                                String s = ((HttpServletRequest) req).getHeader("user-agent");
                                                if (s != null) {
                                                    String cache = (String) req.getAttribute("$$zkagent$$");
                                    Severity: Minor
                                    Found in zweb/src/main/java/org/zkoss/web/servlet/Servlets.java - About 25 mins to fix

                                    Cognitive Complexity

                                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                                    A method's cognitive complexity is based on a few simple rules:

                                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                                    • Code is considered more complex for each "break in the linear flow of the code"
                                    • Code is considered more complex when "flow breaking structures are nested"

                                    Further reading

                                    Method include has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                    Open

                                        public static final void include(ServletContext ctx, ServletRequest request, ServletResponse response, String uri,
                                                Map params, int mode) throws IOException, ServletException {
                                            //        if (log.isDebugEnabled()) log.debug("Including "+uri+" at "+ctx);
                                    
                                            //Note: we don't optimize the include to call ClassWebResource here
                                    Severity: Minor
                                    Found in zweb/src/main/java/org/zkoss/web/servlet/Servlets.java - About 25 mins to fix

                                    Cognitive Complexity

                                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                                    A method's cognitive complexity is based on a few simple rules:

                                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                                    • Code is considered more complex for each "break in the linear flow of the code"
                                    • Code is considered more complex when "flow breaking structures are nested"

                                    Further reading

                                    Similar blocks of code found in 3 locations. Consider refactoring.
                                    Open

                                                    if (j >= 0) {
                                                        ctxroot = "/" + uri.substring(1, j);
                                                        _uri = uri.substring(j);
                                                    } else {
                                                        ctxroot = "/" + uri.substring(1);
                                    Severity: Major
                                    Found in zweb/src/main/java/org/zkoss/web/servlet/Servlets.java and 2 other locations - About 55 mins to fix
                                    zweb/src/main/java/org/zkoss/web/portlet/Portlets.java on lines 121..127
                                    zweb/src/main/java/org/zkoss/web/util/resource/ResourceCaches.java on lines 87..93

                                    Duplicated Code

                                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                    Tuning

                                    This issue has a mass of 66.

                                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                    Refactorings

                                    Further Reading

                                    Similar blocks of code found in 2 locations. Consider refactoring.
                                    Open

                                            private URIIndex(String uri, Locale locale) {
                                                if (uri == null || locale == null)
                                                    throw new IllegalArgumentException("null");
                                                _uri = uri;
                                                _locale = locale;
                                    Severity: Minor
                                    Found in zweb/src/main/java/org/zkoss/web/servlet/Servlets.java and 1 other location - About 35 mins to fix
                                    zcommon/src/main/java/org/zkoss/util/FilterMap.java on lines 47..52

                                    Duplicated Code

                                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                    Tuning

                                    This issue has a mass of 45.

                                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                    Refactorings

                                    Further Reading

                                    There are no issues that match your filters.

                                    Category
                                    Status