zk/src/main/java/org/zkoss/zk/ui/http/WpdExtendlet.java

Summary

Maintainability
F
1 wk
Test Coverage

Method parse has a Cognitive Complexity of 184 (exceeds 5 allowed). Consider refactoring.
Open

    private Object parse(RequestContext reqctx, InputStream is, String path) throws Exception {
        final Element root = new SAXBuilder(true, false, true).build(is).getRootElement();
        final String name = IDOMs.getRequiredAttributeValue(root, "name");
        if (name.length() == 0)
            throw new UiException("The name attribute must be specified, " + root.getLocator() + ", " + path);
Severity: Minor
Found in zk/src/main/java/org/zkoss/zk/ui/http/WpdExtendlet.java - About 3 days 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

File WpdExtendlet.java has 910 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* WpdExtendlet.java

    Purpose:

    Description:
Severity: Major
Found in zk/src/main/java/org/zkoss/zk/ui/http/WpdExtendlet.java - About 2 days to fix

    Method parse has 240 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private Object parse(RequestContext reqctx, InputStream is, String path) throws Exception {
            final Element root = new SAXBuilder(true, false, true).build(is).getRootElement();
            final String name = IDOMs.getRequiredAttributeValue(root, "name");
            if (name.length() == 0)
                throw new UiException("The name attribute must be specified, " + root.getLocator() + ", " + path);
    Severity: Major
    Found in zk/src/main/java/org/zkoss/zk/ui/http/WpdExtendlet.java - About 1 day to fix

      Method retrieve has a Cognitive Complexity of 54 (exceeds 5 allowed). Consider refactoring.
      Open

          protected byte[] retrieve(HttpServletRequest request, HttpServletResponse response, String path)
                  throws ServletException, IOException {
              byte[] data;
              String pkg = null;
              boolean sourceMapEnabled = sourceMapEnabled();
      Severity: Minor
      Found in zk/src/main/java/org/zkoss/zk/ui/http/WpdExtendlet.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 retrieve has 95 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected byte[] retrieve(HttpServletRequest request, HttpServletResponse response, String path)
                  throws ServletException, IOException {
              byte[] data;
              String pkg = null;
              boolean sourceMapEnabled = sourceMapEnabled();
      Severity: Major
      Found in zk/src/main/java/org/zkoss/zk/ui/http/WpdExtendlet.java - About 3 hrs to fix

        Method toByteArray has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
        Open

                @SuppressWarnings("unchecked")
                private byte[] toByteArray(RequestContext reqctx) throws ServletException, IOException {
                    final ByteArrayOutputStream out = new ByteArrayOutputStream();
                    final HttpServletRequest request = reqctx.request;
                    final String main = request != null ? request.getParameter("main") : null;
        Severity: Minor
        Found in zk/src/main/java/org/zkoss/zk/ui/http/WpdExtendlet.java - About 3 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 processWpdForSourcemapIfAny has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
        Open

            private String processWpdForSourcemapIfAny(List<String> paths, String originalPathPrefix, String path) throws Exception {
                final Content content = (Content) _cache.get(path);
                if (content == null) {
                    log.error("Failed to load the resource: " + path);
                    throw new java.io.FileNotFoundException("Failed to load the resource: " + path);
        Severity: Minor
        Found in zk/src/main/java/org/zkoss/zk/ui/http/WpdExtendlet.java - About 3 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

        WpdExtendlet has 26 methods (exceeds 20 allowed). Consider refactoring.
        Open

        public class WpdExtendlet extends AbstractExtendlet<Object> {
            //source map
            public static final String SOURCE_MAP_JAVASCRIPT_PATH = "$zk$sourcemapJsPath"; // for HtmlPageRenders
            private static final String SOURCE_MAP_DIVIDED_WPDS = "$zk$dividedWPDs";
            private static final String SOURCE_MAP_DIVIDED_WPDS_NUMBER = "$zk$dividedWPDsNum";
        Severity: Minor
        Found in zk/src/main/java/org/zkoss/zk/ui/http/WpdExtendlet.java - About 3 hrs to fix

          Method writeAppInfo has 69 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private void writeAppInfo(RequestContext reqctx, OutputStream out, WebApp wapp) throws IOException, ServletException {
                  final String verInfoEnabled = Library.getProperty("org.zkoss.zk.ui.versionInfo.enabled", "true");
                  final boolean exposeVer = "true".equals(verInfoEnabled);
                  final StringBuffer sb = new StringBuffer(256);
                  if (exposeVer)
          Severity: Major
          Found in zk/src/main/java/org/zkoss/zk/ui/http/WpdExtendlet.java - About 2 hrs to fix

            Method processWpdForSourcemapIfAny has 63 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private String processWpdForSourcemapIfAny(List<String> paths, String originalPathPrefix, String path) throws Exception {
                    final Content content = (Content) _cache.get(path);
                    if (content == null) {
                        log.error("Failed to load the resource: " + path);
                        throw new java.io.FileNotFoundException("Failed to load the resource: " + path);
            Severity: Major
            Found in zk/src/main/java/org/zkoss/zk/ui/http/WpdExtendlet.java - About 2 hrs to fix

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

                  private void writeAppInfo(RequestContext reqctx, OutputStream out, WebApp wapp) throws IOException, ServletException {
                      final String verInfoEnabled = Library.getProperty("org.zkoss.zk.ui.versionInfo.enabled", "true");
                      final boolean exposeVer = "true".equals(verInfoEnabled);
                      final StringBuffer sb = new StringBuffer(256);
                      if (exposeVer)
              Severity: Minor
              Found in zk/src/main/java/org/zkoss/zk/ui/http/WpdExtendlet.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 findResourcePath has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
              Open

                  private String findResourcePath(RequestContext reqctx, OutputStream out, String path, String dir, boolean locate, boolean write) throws ServletException, IOException {
                      if (path.startsWith("~./")) path = path.substring(2);
                      else if (path.charAt(0) != '/') path = Files.normalize(dir, path);
                      //source map browser issue and check source map file is available or not
                      String originalPath = "";
              Severity: Minor
              Found in zk/src/main/java/org/zkoss/zk/ui/http/WpdExtendlet.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 toByteArray has 34 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                      @SuppressWarnings("unchecked")
                      private byte[] toByteArray(RequestContext reqctx) throws ServletException, IOException {
                          final ByteArrayOutputStream out = new ByteArrayOutputStream();
                          final HttpServletRequest request = reqctx.request;
                          final String main = request != null ? request.getParameter("main") : null;
              Severity: Minor
              Found in zk/src/main/java/org/zkoss/zk/ui/http/WpdExtendlet.java - About 1 hr to fix

                Method processDynamicWpdWithSourceMapIfAny has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    private byte[] processDynamicWpdWithSourceMapIfAny(HttpServletRequest request, HttpServletResponse response, String pkgWpd, String path) throws Exception {
                        List<String> dividedPaths = splitSourceMapJsPathIfAny(path);
                        StringBuilder sb = new StringBuilder();
                        int index = 0;
                        String lastWpd = null;
                Severity: Minor
                Found in zk/src/main/java/org/zkoss/zk/ui/http/WpdExtendlet.java - About 1 hr to fix

                  Method findResourcePath has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      private String findResourcePath(RequestContext reqctx, OutputStream out, String path, String dir, boolean locate, boolean write) throws ServletException, IOException {
                          if (path.startsWith("~./")) path = path.substring(2);
                          else if (path.charAt(0) != '/') path = Files.normalize(dir, path);
                          //source map browser issue and check source map file is available or not
                          String originalPath = "";
                  Severity: Minor
                  Found in zk/src/main/java/org/zkoss/zk/ui/http/WpdExtendlet.java - About 1 hr to fix

                    Method mergeJavaScript has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                    Open

                        protected byte[] mergeJavaScript(HttpServletRequest request, HttpServletResponse response, String pkgTo,
                                byte[] data) throws ServletException, IOException {
                            ByteArrayOutputStream out = null;
                            Device device = null;
                            final String deviceType = getDeviceType();
                    Severity: Minor
                    Found in zk/src/main/java/org/zkoss/zk/ui/http/WpdExtendlet.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 parse has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                            private Object parse(RequestContext reqctx) throws ServletException, IOException {
                                if (_cnt instanceof SourceInfo)
                                    try {
                                        _cnt = ((SourceInfo) _cnt).parse(reqctx);
                                    } catch (IOException ex) {
                    Severity: Minor
                    Found in zk/src/main/java/org/zkoss/zk/ui/http/WpdExtendlet.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

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

                        private String findResourcePath(RequestContext reqctx, OutputStream out, String path, String dir, boolean locate, boolean write) throws ServletException, IOException {
                    Severity: Minor
                    Found in zk/src/main/java/org/zkoss/zk/ui/http/WpdExtendlet.java - About 45 mins to fix

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

                          private void outErrReloads(RequestContext reqctx, Configuration config, StringBuffer sb, Object[][] infs) {
                              for (int j = 0; j < infs.length; ++j) {
                                  if (j > 0)
                                      sb.append(',');
                                  sb.append('\'').append(infs[j][0]).append("':'");
                      Severity: Minor
                      Found in zk/src/main/java/org/zkoss/zk/ui/http/WpdExtendlet.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

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

                          private boolean writeResource(RequestContext reqctx, OutputStream out, String path, String dir, boolean locate) throws IOException, ServletException {
                      Severity: Minor
                      Found in zk/src/main/java/org/zkoss/zk/ui/http/WpdExtendlet.java - About 35 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                    return null;
                        Severity: Major
                        Found in zk/src/main/java/org/zkoss/zk/ui/http/WpdExtendlet.java - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                      if (isNotModified) return null;
                          Severity: Major
                          Found in zk/src/main/java/org/zkoss/zk/ui/http/WpdExtendlet.java - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                                return ("(function(){zk.setLoaded('" + lastPart.replace("$.wpd", "") + "');})()").getBytes();
                            Severity: Major
                            Found in zk/src/main/java/org/zkoss/zk/ui/http/WpdExtendlet.java - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                                  return ("(function(){zk._p=zkpi('" + pkgName + "');})()").getBytes();
                              Severity: Major
                              Found in zk/src/main/java/org/zkoss/zk/ui/http/WpdExtendlet.java - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                        return pkg != null && !sourceMapEnabled ? mergeJavaScript(request, response, pkg, data) : data;
                                Severity: Major
                                Found in zk/src/main/java/org/zkoss/zk/ui/http/WpdExtendlet.java - About 30 mins to fix

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

                                      private byte[] processDynamicWpdWithSourceMapIfAny(HttpServletRequest request, HttpServletResponse response, String pkgWpd, String path) throws Exception {
                                          List<String> dividedPaths = splitSourceMapJsPathIfAny(path);
                                          StringBuilder sb = new StringBuilder();
                                          int index = 0;
                                          String lastWpd = null;
                                  Severity: Minor
                                  Found in zk/src/main/java/org/zkoss/zk/ui/http/WpdExtendlet.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 isWpdContentRequired has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      private boolean isWpdContentRequired(String pkg, Element root) {
                                          for (LanguageDefinition langdef : LanguageDefinition.getByDeviceType(getDeviceType()))
                                              if (langdef.getJavaScriptPackagesWithMerges().contains(pkg)) return true;
                                  
                                          for (Iterator it = root.getElements("script").iterator(); it.hasNext();) {
                                  Severity: Minor
                                  Found in zk/src/main/java/org/zkoss/zk/ui/http/WpdExtendlet.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 2 locations. Consider refactoring.
                                  Open

                                          if (_webctx.shallCompress(request, "wpd") && data.length > 200) {
                                              byte[] bs = Https.gzip(request, response, null, data);
                                              if (bs != null)
                                                  data = bs; //yes, browser support compress
                                          }
                                  Severity: Minor
                                  Found in zk/src/main/java/org/zkoss/zk/ui/http/WpdExtendlet.java and 1 other location - About 45 mins to fix
                                  zk/src/main/java/org/zkoss/zk/ui/http/WcsExtendlet.java on lines 157..161

                                  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 56.

                                  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