Question 1 - Answer 1
Question 2 - Answer 2
Question 3 - Answer 3

More duplicates of this pattern from the same user:

Iterator for binary tree - pre, in, and post order iterators
Isomorphic trees verification
Return the next right node
Print all nodes that are at distance k from a leaf node
Create a binary tree, code review request
Morris inorder traversal
Print left view of the tree
Get the levels of a binary tree
Serializing/deserializing binary tree in most space-efficient way (Yeah, this one too. It doesn't look like it at first but on closer inspection it does)
Join/ connect all levels of Binary tree without any aux storage
Preorder traversal of binary tree to produce formatted string
Inorder traversal of a tree without recursion or stack
Least common ancestor in binary tree (Has check for null, but not empty array)
Detect a complete binary tree
Reverse values of alternate nodes of the tree
Find all nodes in tree, without a sibling
Check if all leaves are at same level
Search an element/item in an n-ary tree (uses array, but my answer is still valid)
Given a Perfect Binary Tree, reverse the alternate level nodes of the binary tree
Transform a Binary Search Tree into a Greater Sum Tree
Detect if a tree is complete binary tree

If a question duplicates the code...

class BinaryTrees<T> {

    private TreesNode<T> root;

    public BinaryTrees(List<T> items) {

    private void create (List<T> items) {        
        root = new TreesNode<T>(items.get(0));


class BinaryTree<T> {

    private Node<T> root;

    public BinaryTree(Node<T> root) {
        this.root = root;

    public BinaryTree(List<T> items) {

    private void create (List<? extends T> items) {
        root = new Node<T>(items.get(0));

with answer

Bug: IndexOutOfBoundsException on empty list in BinaryTree(s).create(List<(? extends )T> items). You don't have a comment stating you need to input a list containing at least something. Consider returning IllegalArgumentException and adding a comment.

(Note: I have referred to the proper names and function signatures in both answers. My answer is not generic.)

Am I allowed to post a duplicate answer? I can come up with a couple of arguments for yes and for no...

  • Yes, because each question stands on its own.

  • Yes, because I might not have noticed the duplicate.

    • What if I did? How are you going to verify this?
  • No, because the answer is to the benefit of the asker, so duplicating your answer won't help.

    • If I add one point that is not duplicated, should I remove my duplicated points? If anyone brings up these (valid) points, should their answer get deleted as a duplicate? How are they supposed to know?
  • No, because if you duplicate your answer then editing it requires us to change it in both posts.

Which of these reasons is valid, and why?

Additionally... does it make for a good answer?

If this is allowed, I intend to post my answer on each and every of these questions if the points haven't been made yet.

Update: I have posted answers on the questions where answerers didn't mention this issue yet.

  • \$\begingroup\$ I have notified JavaDeveloper that his questions are being discussed. \$\endgroup\$
    – rolfl
    Sep 17, 2014 at 10:34
  • \$\begingroup\$ Note that your answers are triggering auto-flags in the system: Duplicate Answer(auto) \$\endgroup\$
    – rolfl
    Sep 17, 2014 at 11:24
  • \$\begingroup\$ @rolfl I have faith that you'll handle them properly. I'm almost done. \$\endgroup\$
    – Pimgd
    Sep 17, 2014 at 11:26
  • \$\begingroup\$ @rolfl I'm also trying to add things other than this when I spot them, so sometimes it's not a total duplicate. \$\endgroup\$
    – Pimgd
    Sep 17, 2014 at 11:34
  • \$\begingroup\$ @Pimgd nvm. Wrong place. \$\endgroup\$
    – JaDogg
    Sep 23, 2014 at 1:03

3 Answers 3


Yes, and No

Let's be clear here, the code works for the purpose given. The code presented will never be called in a way that exposes that bug, so is it a bug? Not for the asker. That code is not intended for review but is intended to provide background for the actual algorithm/process he wants to accomplish.

The bug is only a bug if you extend the usage of the code beyond its intended requirements, which would be a valid concern in a review,

Is this worth pointing out in a review...? Yes. Is basing a review entirely on part of the code that is 'support' code meaningful? Sure, there's nothing stopping that. You are free to review any, and all aspects of the code.

Are you free to post the same, or substantially the same answer to multiple posts? Yes

You also have other options:

  1. just ignore the questions
  2. answer that, in combination with other reviews aspects

Now, are your answers good answers?

They serve a purpose, but a weak one. They provide little, or no benefit to JavaDeveloper because he will not see that particular code as central to the question he asks.

Your answers do answer a question that is otherwise unanswered, so that's good.

The answers will not really satisfy you, personally... it will be boring, and unfulfilling.

On a personal note, I tend to ignore JavaDeveloper questions. I have answered many of them in the past too, and find myself repeating myself again, and again. I find myself repeating myself again, and again. I don't like reading through the same 'boilerplate' code each time just to see the subtle differences one question has compared to another. It does not satisfy me, so I just don't do it. I scan his questions to see if there's something of 'unusual' interest, or to see whether he's learned something significant from previous times. If it looks like something I have seen before, I tend to 'move on'.

I cannot find anything technically wrong, or off-topic, about his questions from a Code Review site perspective, so the questions are not duplicates, or off topic, but at the same time, they have just lost interest for me (mostly).

If you have the energy to go though and provide the same reviews to multiple different questions, then you can do it, but be aware that the value added is probably low, and since you will not, for the most part, be addressing anything central to the asker's main concerns, you will likely not gather much in the way of upvotes or accepts.

  • 1
    \$\begingroup\$ "I have answered many of them in the past too, and find myself repeating myself again, and again. I find myself repeating myself again, and again." Was that intentional? \$\endgroup\$
    – Pimgd
    Sep 17, 2014 at 11:02
  • \$\begingroup\$ Additionally: My core point is not "It's a bug!", but rather this: "Supplying empty list gives IndexOutOfBoundsException. You should throw IllegalArgumentException instead". \$\endgroup\$
    – Pimgd
    Sep 17, 2014 at 11:04
  • 2
    \$\begingroup\$ Of course it was intentional, it was intentional. Your answer starts with: "A minor bug: ..." and my point is that it will never get an empty list. \$\endgroup\$
    – rolfl
    Sep 17, 2014 at 11:19

For me an answer is related to a question.
An answer about formatting and naming the vars correct is also a very common answer.
Do we have to redirect them to answers of the other questions for that?

That said, I think I would vote to close the second one as duplicate or broken code if the first answer already has the duplicate answer before the posting of the second question.


  • Asked by the same person.
  • A lot of duplicated code.(no follow up cause it's a different issue)
  • Created same fault as in first topic.
  • With the copying of the fault I'm asking myself, do he learn from the answers on previous questions?

In my opinion :

We really want to help users and help them improve themselves.
This is possible if users listen to us.
A user can't improve if they don't take valuable information to new questions/code.

So if most of the code in a second question is copy paste from earlier question => it's duplicated code so duplicated faults and you get duplicated answers.

  • 3
    \$\begingroup\$ The duplicate answers were posted 5 minutes apart. The "duplicate" questions were posted 10 days apart. The answers were posted after both questions had been posted. He hasn't had the time to learn yet. \$\endgroup\$
    – Pimgd
    Sep 17, 2014 at 9:08
  • \$\begingroup\$ Your correct about that, edited mine answer. \$\endgroup\$
    – chillworld
    Sep 17, 2014 at 9:14
  • 1
    \$\begingroup\$ I agree with the first point: Making canonical answers is a bit silly. However... it turns out there are 25 questions where my answer is valid. Do I get to post on all of them? \$\endgroup\$
    – Pimgd
    Sep 17, 2014 at 9:33

This started off with a two-way duplicate; That is, two questions contained the same code-pattern.

In that light, I would have said "each question is separate". If a question happens to contain the same code(pattern) as another, it's perfectly valid to post answers on both questions listing the same points. Just make sure your answer is valid (if they say "It only accepts non-empty lists" then the point "it fails on empty list" is not a valid point. "Add a comment that it doesn't accept empty lists" is.).

However... I have found 25 questions with the same code(pattern). 25.

Is it valid to post it on 25 questions?

Legally: Yes. Each question is separate.

The real question is "Do you think that will help anyone?". ... And I'd say yes to that too. It won't help the asker, but it will help anyone who stumbles on the question.

  • 1
    \$\begingroup\$ indeed, when I come up one of those 25 questions, I'm not going to look for same code pattern to search for a valid answer so still valid, how stupid it can sound \$\endgroup\$
    – chillworld
    Sep 17, 2014 at 9:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .