zk/src/main/java/org/zkoss/zk/scripting/bsh/BSHInterpreter.java

Summary

Maintainability
F
6 days
Test Coverage

File BSHInterpreter.java has 572 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* BSHInterpreter.java

    Purpose:
        
    Description:
Severity: Major
Found in zk/src/main/java/org/zkoss/zk/scripting/bsh/BSHInterpreter.java - About 1 day to fix

    Method write has a Cognitive Complexity of 60 (exceeds 5 allowed). Consider refactoring.
    Open

        /*package*/ static void write(NameSpace ns, ObjectOutputStream s, Filter filter) throws IOException {
            //1. variables
            final String[] vars = ns.getVariableNames();
            for (int j = vars != null ? vars.length : 0; --j >= 0;) {
                final String nm = vars[j];
    Severity: Minor
    Found in zk/src/main/java/org/zkoss/zk/scripting/bsh/BSHInterpreter.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 read has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
    Open

        /*package*/ static void read(NameSpace ns, ObjectInputStream s) throws IOException {
            for (;;) {
                try {
                    final String nm = (String) s.readObject();
                    if (nm == null)
    Severity: Minor
    Found in zk/src/main/java/org/zkoss/zk/scripting/bsh/BSHInterpreter.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 getFromScope has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

            protected Object getFromScope(String name) {
                final BSHInterpreter ip = getInterpreter(_scope);
                final Scope curr = ip != null ? ip.getCurrent() : null;
                if (curr == null)
                    return getImplicit(name); //ignore scope
    Severity: Minor
    Found in zk/src/main/java/org/zkoss/zk/scripting/bsh/BSHInterpreter.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

    BSHInterpreter has 31 methods (exceeds 20 allowed). Consider refactoring.
    Open

    public class BSHInterpreter extends GenericInterpreter implements SerializableAware, HierarchicalAware {
        /*package*/ static final Logger log = LoggerFactory.getLogger(BSHInterpreter.class);
    
        /** A variable in {@link Scope}. The value is an instance of
         * BeanShell's NameSpace.
    Severity: Minor
    Found in zk/src/main/java/org/zkoss/zk/scripting/bsh/BSHInterpreter.java - About 3 hrs to fix

      Method write has 93 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          /*package*/ static void write(NameSpace ns, ObjectOutputStream s, Filter filter) throws IOException {
              //1. variables
              final String[] vars = ns.getVariableNames();
              for (int j = vars != null ? vars.length : 0; --j >= 0;) {
                  final String nm = vars[j];
      Severity: Major
      Found in zk/src/main/java/org/zkoss/zk/scripting/bsh/BSHInterpreter.java - About 3 hrs to fix

        Method getFromScope has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
        Open

                protected Object getFromScope(String name) {
                    final Scope curr = getCurrent();
                    if (curr == null) //no scope allowed
                        return getImplicit(name);
        
        
        Severity: Minor
        Found in zk/src/main/java/org/zkoss/zk/scripting/bsh/BSHInterpreter.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 getVariableImpl has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

                protected Variable getVariableImpl(String name, boolean recurse) throws UtilEvalError {
                    //Note: getVariableImpl returns null if not defined,
                    //while getVariable return Primitive.VOID if not defined
        
                    //Tom M Yeh: 20060606:
        Severity: Minor
        Found in zk/src/main/java/org/zkoss/zk/scripting/bsh/BSHInterpreter.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 read has 59 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            /*package*/ static void read(NameSpace ns, ObjectInputStream s) throws IOException {
                for (;;) {
                    try {
                        final String nm = (String) s.readObject();
                        if (nm == null)
        Severity: Major
        Found in zk/src/main/java/org/zkoss/zk/scripting/bsh/BSHInterpreter.java - About 2 hrs to fix

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

                  protected Variable getVariableImpl(String name, boolean recurse) throws UtilEvalError {
                      //Note: getVariableImpl returns null if not defined,
                      //while getVariable return Primitive.VOID if not defined
          
                      //Tom M Yeh: 20060606:
          Severity: Minor
          Found in zk/src/main/java/org/zkoss/zk/scripting/bsh/BSHInterpreter.java - About 1 hr to fix

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

                protected Object get(Scope scope, String name) {
                    if (scope != null) {
                        final NameSpace bshns = prepareNS(scope);
                        //note: we have to create NameSpace (with prepareNS)
                        //to have the correct chain
            Severity: Minor
            Found in zk/src/main/java/org/zkoss/zk/scripting/bsh/BSHInterpreter.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 getFromScope has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                    protected Object getFromScope(String name) {
                        final BSHInterpreter ip = getInterpreter(_scope);
                        final Scope curr = ip != null ? ip.getCurrent() : null;
                        if (curr == null)
                            return getImplicit(name); //ignore scope
            Severity: Minor
            Found in zk/src/main/java/org/zkoss/zk/scripting/bsh/BSHInterpreter.java - About 1 hr to fix

              Method getFromScope has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                      protected Object getFromScope(String name) {
                          final Scope curr = getCurrent();
                          if (curr == null) //no scope allowed
                              return getImplicit(name);
              
              
              Severity: Minor
              Found in zk/src/main/java/org/zkoss/zk/scripting/bsh/BSHInterpreter.java - About 1 hr to fix

                Consider simplifying this complex logical expression.
                Open

                                    if ((val == null || (val instanceof Serializable) || (val instanceof Externalizable))
                                            && !(val instanceof Component) && (filter == null || filter.accept(nm, val))) {
                                        s.writeObject(nm);
                                        s.writeObject(val);
                                    }
                Severity: Major
                Found in zk/src/main/java/org/zkoss/zk/scripting/bsh/BSHInterpreter.java - About 40 mins to fix

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

                      protected void set(Scope scope, String name, Object val) {
                          if (scope != null) {
                              final NameSpace bshns = prepareNS(scope);
                              //note: we have to create NameSpace (with prepareNS)
                              //to have the correct chain
                  Severity: Minor
                  Found in zk/src/main/java/org/zkoss/zk/scripting/bsh/BSHInterpreter.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 contains has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                      protected boolean contains(Scope scope, String name) {
                          if (scope != null) {
                              final NameSpace bshns = prepareNS(scope);
                              //note: we have to create NameSpace (with prepareNS)
                              //to have the correct chain
                  Severity: Minor
                  Found in zk/src/main/java/org/zkoss/zk/scripting/bsh/BSHInterpreter.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 val;
                  Severity: Major
                  Found in zk/src/main/java/org/zkoss/zk/scripting/bsh/BSHInterpreter.java - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                return val != null ? val : getImplicit(name);
                    Severity: Major
                    Found in zk/src/main/java/org/zkoss/zk/scripting/bsh/BSHInterpreter.java - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                  return val != null || comp.hasAttributeOrFellow(name, false) ? val : getImplicit(name);
                      Severity: Major
                      Found in zk/src/main/java/org/zkoss/zk/scripting/bsh/BSHInterpreter.java - About 30 mins to fix

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

                            /*package*/ static BSHInterpreter getInterpreter(Scope scope) {
                                Page owner = getPage(scope);
                                if (owner != null) {
                                    for (Iterator it = owner.getLoadedInterpreters().iterator(); it.hasNext();) {
                                        final Object ip = it.next();
                        Severity: Minor
                        Found in zk/src/main/java/org/zkoss/zk/scripting/bsh/BSHInterpreter.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

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

                                        if (exec != null) {
                                            Object val = exec instanceof ExecutionCtrl ? ((ExecutionCtrl) exec).getExtraXelVariable(name)
                                                    : null;
                                            if (val != null)
                                                return val;
                        Severity: Minor
                        Found in zk/src/main/java/org/zkoss/zk/scripting/bsh/BSHInterpreter.java and 1 other location - About 50 mins to fix
                        zk/src/main/java/org/zkoss/zk/scripting/bsh/BSHInterpreter.java on lines 517..525

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

                        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

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

                                        if (exec != null && exec != curr) {
                                            Object val = exec instanceof ExecutionCtrl ? ((ExecutionCtrl) exec).getExtraXelVariable(name)
                                                    : null;
                                            if (val != null)
                                                return val;
                        Severity: Minor
                        Found in zk/src/main/java/org/zkoss/zk/scripting/bsh/BSHInterpreter.java and 1 other location - About 50 mins to fix
                        zk/src/main/java/org/zkoss/zk/scripting/bsh/BSHInterpreter.java on lines 464..472

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

                        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

                                for (;;) {
                                    try {
                                        final String nm = (String) s.readObject();
                                        if (nm == null)
                                            break; //no more
                        Severity: Minor
                        Found in zk/src/main/java/org/zkoss/zk/scripting/bsh/BSHInterpreter.java and 1 other location - About 50 mins to fix
                        zk/src/main/java/org/zkoss/zk/scripting/bsh/BSHInterpreter.java on lines 730..742

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

                        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

                                for (;;) {
                                    try {
                                        final String nm = (String) s.readObject();
                                        if (nm == null)
                                            break; //no more
                        Severity: Minor
                        Found in zk/src/main/java/org/zkoss/zk/scripting/bsh/BSHInterpreter.java and 1 other location - About 50 mins to fix
                        zk/src/main/java/org/zkoss/zk/scripting/bsh/BSHInterpreter.java on lines 744..756

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

                        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

                                    if (bshns != _bshns) {
                                        try {
                                            Object result = Primitive.unwrap(bshns.getVariable(name));
                                            if (result instanceof ClassIdentifier) {
                                                return null; // Class is not a variable
                        Severity: Minor
                        Found in zk/src/main/java/org/zkoss/zk/scripting/bsh/BSHInterpreter.java and 1 other location - About 40 mins to fix
                        zk/src/main/java/org/zkoss/zk/scripting/bsh/BSHInterpreter.java on lines 165..175

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

                        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

                            protected Object get(String name) {
                                try {
                                    Object result = Primitive.unwrap(_ip.get(name));
                                    if (result instanceof ClassIdentifier) {
                                        return null; // Class is not a variable
                        Severity: Minor
                        Found in zk/src/main/java/org/zkoss/zk/scripting/bsh/BSHInterpreter.java and 1 other location - About 40 mins to fix
                        zk/src/main/java/org/zkoss/zk/scripting/bsh/BSHInterpreter.java on lines 182..192

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

                        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