Ambiguity in deciding upper and lower limits of definite integration while doing substitutions $
I = \int_{0}^{\infty} \frac{x}{({x^2 + 1)(1+x)}} \,\mathrm{d}x
$
Let $x=\tan(\theta)$ gives $\mathrm{d}\theta= \frac{\mathrm{d}x}{({x^2 + 1)}}$
$I= \int_0^{\pi/2} \frac{\tan \theta}{1 + \tan \theta} \,\mathrm{d}\theta 
$
$= \int_0^{\pi/2} \frac{\tan (\pi/2-\theta)}{1 + \tan(\pi/2-\theta)} \,\mathrm{d}\theta$
$ =\int_0^{\pi/2} \frac{1}{1 + \tan \theta} \,\mathrm{d}\theta$
$1^{st} $ and $3^{rd}$ gives
$2I= \int_0^{\pi/2}  \,\mathrm{d}\theta \rightarrow I=\frac{\pi}{4}
$

Main doubt: Why can't we take $ \{ x \rightarrow \infty \} $ in upper limit of integration as $\{ \tan(\theta) \rightarrow 3 \pi / 2 \} $ ?

That is
$I= \int_0^{3\pi/2} \frac{\tan \theta}{1 + \tan \theta} \,\mathrm{d}\theta $
$= \int_0^{3\pi/2} \frac{\tan (3\pi/2-\theta)}{1 + \tan(3\pi/2-\theta)} \,\mathrm{d}\theta$
$ =\int_0^{3\pi/2} \frac{1}{1 + \tan \theta} \,\mathrm{d}\theta$
$1^{st} $ and $3^{rd}$ gives
$2I= \int_0^{3\pi/2}  \,\mathrm{d}\theta \rightarrow I=\frac{3\pi}{4}
$

which yeilds different answer.

Above Question is just an example for the Main doubt I have asked.
The below Question is closely related to and subset of my Question (which I do not knew while posting my question). So I am linking it for future readers. Why doesn't trig substitution work for definite integrals?
 A: In addition to your question, let's address two common errors that are recited on MSE often.  We'll finish with a third, entirely different, error related to the work you present and maybe one or two follow-ups.
Let's agree on one piece of terminology.  The ($u$-)substitution formula is
$$  \int_a^b f(u(x)) \cdot u'(x) \,\mathrm{d}x = \int_c^d f(u) \,\mathrm{d}u  $$
Let's say that substitution is used in "simplifying direction" when used left-to-right by finding a subexpression in the integrand in front of us to be $u$, sufficient to replace all other occurrence of $x$ with expressions in $u$, and having a derivative that is (close enough) to explicitly present that we can rewrite "$u'(x)\,\mathrm{d}x$" to "$\mathrm{d}u$".
Let us also say that the substitution formula is used in the "complexifying direction" when used right-to-left by replacing the variable in an integral by a more complicated expression and replacing the differential of the original variable with a more complicated expression.  (Trigonometric substitution is an example of going in the complexifying direction.)
"The substitution function must be bijective."
This is blatantly false in the simplifying direction.  Nearly every substitution by polynomial is an immediate counterexample.  For instance, $$
I = \int_{-2}^{1} \frac{2x}{\sqrt{x^2 + 1}} \,\mathrm{d}x
$$
Notice that this integrand is an odd function, so this integral is equal to $\int_{-2}^{-1} \cdots = -\int_1^2 \cdots$.  Happily, this cancellation is automatically implemented with the substitution $u = x^2 + 1$, which is very far from bijective (both globally, relevant if we imagine we solve for an antiderivative then switch back the variable $x$, and on the interval of integration, relevant if we transform the interval of integration to the variable $u$ and evaluate there.)
$$  I = \int_{5}^{2} u^{-1/2}\,\mathrm{d}u = 2(\sqrt{2} - \sqrt{5})  \text{.}  $$
Notice that we took no action to implement symmetry or to tease out the effect of cancellation due to non-bijectivity.  That all happens automatically.
"The substitution function must be bijective in the complexifying direction."
This claim is also false, but at least more interesting things can happen in the complexifying direction.  Let's consider a very common example of using substitution in this direction, trigonometric substitution.  Consider the integral
$$  J = \int_{-1/2}^{1/2} \frac{1}{\sqrt{1-u^2}} \,\mathrm{d}u  $$
Make the substitution $u = \sin x$, $\mathrm{d}u = \cos x \,\mathrm{d}x$.  Sine is not bijective, although it has infinitely many restrictions that are bijective.  Continuing as usual, which means choosing the restriction of sine to the interval $[-\pi/2, \pi/2]$ to match the conventional branch of the arcsine ...
\begin{align*}
J &= \int_{\arcsin(-1/2)}^{\arcsin(1/2)} \frac{\cos x}{\sqrt{1 - \sin^2 x}} \,\mathrm{d}x  \\
  &= \int_{\arcsin(-1/2)}^{\arcsin(1/2)} \frac{\cos x}{|\cos x|} \,\mathrm{d}x  \\
  &= \int_{-\pi/6}^{\pi/6} \begin{cases}
1  ,&  \cos x \geq 0  \\
-1  ,&  \cos x < 0
\end{cases} \,\mathrm{d}x  \\
&= 1\cdot \left( \frac{\pi}{6} - \frac{-\pi}{6} \right)  \\
&= \frac{\pi}{3}
\end{align*}
So, much as in the writing you have, let's ignore the restriction.  If bijectivity is required, we'll see some source of error creep into this computation.
\begin{align*}
\widetilde{J} &= \int_{\arcsin(-1/2)}^{2\pi + \arcsin(1/2)} \frac{\cos x}{\sqrt{1 - \sin^2 x}} \,\mathrm{d}x  \\
  &= \int_{\arcsin(-1/2)}^{2\pi + \arcsin(1/2)} \frac{\cos x}{|\cos x|} \,\mathrm{d}x  \\
  &= \int_{-\pi/6}^{13 \pi/6} \begin{cases}
1  ,&  \cos x \geq 0  \\
-1  ,&  \cos x < 0
\end{cases} \,\mathrm{d}x  \\
  &= \int_{-\pi/6}^{\pi/2} \begin{cases}
1  ,&  \cos x \geq 0  \\
-1  ,&  \cos x < 0
\end{cases} \,\mathrm{d}x  \\
  &\qquad{}+ \int_{\pi/2}^{3\pi/2} \begin{cases}
1  ,&  \cos x \geq 0  \\
-1  ,&  \cos x < 0
\end{cases} \,\mathrm{d}x  \\
  &\qquad{}+ \int_{3\pi/2}^{13\pi/6} \begin{cases}
1  ,&  \cos x \geq 0  \\
-1  ,&  \cos x < 0
\end{cases} \,\mathrm{d}x  \\
  &= 1 \cdot \left( \frac{\pi}{2} - \frac{-\pi}{6} \right)  \\
  &\qquad{}+ (-1)\left(\frac{3\pi}{2} - \frac{\pi}{2}\right)  \\
  &\qquad{}+ 1 \cdot \left( \frac{13\pi}{6} - \frac{3\pi}{2} \right)  \\
  &= \frac{\pi}{3}
\end{align*}
The part you probably were not expecting was splitting the interval of integration into subintervals, on each of which either cosine is positive or cosine is negative.  This simplified evaluating the piecewise integrand by partitioning into subintervals on each of which only one piece of the integrand was relevant.
If you work through carefully, you'll see that the extra period of sine (hiding within the second integral) was used to cancel the extra half-periods in the first and third integrals.
"So the thing I wrote about tangent must work."
Nope.  First, when's the last time you spent any time at all really thinking about $\sqrt{y^2} = |y|$ and how that means you should be breaking up the intervals of integration to facilitate integration by having only one sign of $y$ or the other present in each interval?  Also, when is the last time you pushed the "$\sin^{-1}$" button on your calculator and actually reminded yourself that
$$  \sin x = \frac{1}{2}  \quad \iff \quad  x \in \left\{ \frac{\pi}{6} + 2 \pi k \mid k \in \Bbb{Z} \right\} \cup  \left\{ \pi - \frac{\pi}{6} + 2 \pi k \mid k \in \Bbb{Z} \right\}  $$
is a pair of infinite families of angles giving $1/2$ as their sine?  Since "no one" ever thinks about these facts, we teach trigonometric substitution and other complexifying uses of substitution by ignoring all of this.  If you ignore all of this, bijectivity is required to get correct answers.  But the substitution theorem makes no such requirement.
Second, you evaluated that "long" integral using the fundamental theorem of calculus (part 2), by using one of its antiderivatives to evaluate the definite integral.  But the way it is usually stated, this application requires that the integrand is continuous.  Your tangent integrand is not continuous.  Sometimes, a version that applies to more integrands is stated, that only requires that the integrand is integrable.  Your tangent integrand is not integrable.  So your use of the fundamental theorem to evaluate this integral is incorrect.
The problem with your integral isn't (really) about substitution.
$$  K = \int_0^{3\pi/2} \frac{\tan \theta}{1 + \tan \theta} \,\mathrm{d}\theta  $$
is discontinuous at $\theta = 3\pi/4$.  This is an infinite discontinuity (approaching $\infty$ from the left and $-\infty$ from the right).  This integrand is also discontinuous at $\pi/2$ and $3\pi/2$, but those discontinuities are removable.  Strictly, we should treat them by the same methods as the infinite (and jump) discontinuities, but I choose to use later knowledge ("integration doesn't notice removable discontinuities") and ignore these two discontinuities.
The usual method, of dealing with discontinuities (q.v. "improper integral") is to "sneak up" on them using (several) integrals on whose intervals the integrand is continuous, using one-sided limits to squeeze the endpoints of these intervals right up to the discontinuities.
\begin{align*}
K &= \lim_{\ell \rightarrow \frac{3\pi}{4}^-}\int_0^{\ell} \frac{\tan \theta}{1 + \tan \theta} \,\mathrm{d}\theta  \\
  &\qquad{}+ \lim_{r \rightarrow \frac{3\pi}{4}^+}\int_{r}^{3\pi/2} \frac{\tan \theta}{1 + \tan \theta} \,\mathrm{d}\theta
\end{align*}
Neither of these limits exist, so $K$ does not converge.  (The limit from the left diverges to $\infty$ and the limit from the right diverges to $-\infty$.  And we don't do arithmetic with infinities (until you are in Real Analysis, and even there you don't pretend $\infty + -\infty$ has a value).)
"Oh, so the only thing wrong with the work in the picture is the aggressive discontinuity."
Also nope.  There is a subtlety, specific to complexifying substitutions that introduce non-removable discontinuities.  It's actually much more insidious than what the "must be bijective" camp thinks...
Let's do an easier example.  Everyone who has learned
$$  \int \frac{1}{x} \,\mathrm{d}x = \ln |x| + C, x \neq 0  \text{.}  $$
raise your hand.  Thanks.  Hands down.  This is also wrong by being incomplete.
What's the derivative of
$$  f(x) = \begin{cases}
\ln(x) - \pi  ,&  x > 0  \\
\ln(-x) + 7  ,&  x < 0  \\
\end{cases}  \text{?}  $$
We compute \begin{align*}
\frac{\mathrm{d}}{\mathrm{d}x} f(x) 
    &= \frac{\mathrm{d}}{\mathrm{d}x} \begin{cases}
\ln(x) - \pi  ,&  x > 0  \\
\ln(-x) + 7  ,&  x < 0  \\
\end{cases}  \\
    &= \begin{cases}
\frac{\mathrm{d}}{\mathrm{d}x} (\ln(x) - \pi)  ,&  x > 0  \\
\frac{\mathrm{d}}{\mathrm{d}x} (\ln(-x) + 7)  ,&  x < 0  \\
\end{cases}  \\
    &= \begin{cases}
\frac{\mathrm{d}}{\mathrm{d}x} (\ln(|x|)) - 0  ,&  x > 0  \\
\frac{\mathrm{d}}{\mathrm{d}x} (\ln(|x|)) + 0  ,&  x < 0  \\
\end{cases}  \\
    &= \begin{cases}
1/x  ,&  x > 0  \\
1/x  ,&  x < 0  \\
\end{cases}  \\
    &= 1/x, x \neq 0  \text{.}
\end{align*}
That is,
$$  \int \frac{1}{x} \,\mathrm{d}x = \begin{cases} \ln |x| + C_1  ,&  x > 0  \\ 
\ln |x| + C_2  ,&  x < 0  \\ \end{cases}  \text{,}  $$
where $C_1$ and $C_2$ are independent constants.  We get two constants because $\ln|x|$ has an infinite discontinuity at $x = 0$.  There is no way to enforce a requirement like "the limit from the left matches the limit from the right".  The two sides of the function are free to vertically translate independently and every choice of a pair of vertical translations gives another antiderivative of $1/x$ (with respect to $x$).
Of course, we're always lazy and we choose $0$ for our constants of integration when we select a particular antiderivative to use to evaluate a definite integral.
This choice of multiple constants shows up in your tangent example.  We indicate that the integrand is restricted to the interval $0 \leq \theta \leq 3 \pi /2$ to avoid having infinitely many pieces in the piecewise antiderivative.  Assuming $\theta \neq 3\pi/4$,
$$  \int \left. \frac{\tan \theta}{1+ \tan \theta}  \right|_{0 \leq \theta \leq 3 \pi /2} \,\mathrm{d}\theta = \frac{1}{2} \begin{cases}
\theta - \ln \left| \cos \theta + \sin \theta \right| + C_1  ,&  0 \leq \theta < 3\pi/4  \\
\theta - \ln \left| \cos \theta + \sin \theta \right| + C_2  ,&  3\pi/4 < \theta \leq 3\pi/2  \\
\end{cases}  $$
It does not show up in my example of complexifying substitution using the sine because the various branches of the arcsine join up continuously.  This is one of the reasons that the three integrals produced the desired cancellation.  (If you choose to work through the example using different branches of the arcsine, you will again get multiple definite integrals and the evaluations at the endpoints will pairwise cancel, leaving a difference equivalent to the one produced when you just have one integral using the conventional branch of the arcsine.)
Okay...  Why does this matter?  The formula from the fundamental theorem of calculus part two for evaluating definite integrals only works because, when you pick a particular antiderivative, you pick one member of the bag of functions $F(x) + C$, for instance, $F(x) + 1$.  Then, in the formula, the choice of constant cancels out:
$$  (F(b) + 1) - (F(a) + 1) = F(b) - F(a)  \text{.}  $$
Any choice for that one constant cancels out.  If we are working with different branches of a continuous function, continuity restricts our choice of constant on other branches.  But, when continuity doesn't restrict the choice, the cancellation fails.  Say we choose $C_1 = 1$ and $C_2 = 2$ in the above antiderivative of $\frac{\tan \theta}{1 + \tan \theta}$, then the two points at which we evaluate it have different constants, so the cancellation the fundamental theorem relies upon does not exist (which we know, because the fundamental theorem has hypotheses this integrand does not meet).  Since the hypotheses are not met, the consequences of the theorem are not guaranteed and evaluating the integral by this method fails.
