Can an integral of a function that is not well behaved be finite? Consider the following integral which gives the time period of simple pendulum where $\theta_0$ is the initial inclination of pendulum with vertical. 
T=$\sqrt{l/g}\int_0^{\theta_0}\dfrac{d\theta}{\sqrt{cos\theta-cos\theta_0}}$
As we can see the function is not well behaved at $\theta=\theta_0$
but rewriting the integral into elliptic integral (by making substitution $sin\zeta=\frac{sin\theta/2}{sin\theta_0/2}$) gives  
T=$\sqrt{l/g}\int_0^{\pi/2}\dfrac{d\zeta}{\sqrt{1-k^2sin^2\zeta}}$
which is well behaved.
As we all know time period of a simple pendulum is finite value. And intutively the first integral above should give a infinite value though the second integral solves the problem. How is this possible?
 A: The first integral does not give an infinite value, for the same reason that an infinite series can converge, or more to the point
$$\int_0^1 \frac{dx}{\sqrt{x}} =\int_0^1 \frac{dx}{\sqrt{1-x}} = 2 < \infty.$$
The integrand can have a singularity yet still be integrable.
Obviously this integral of $1/\sqrt{x}$ can be evaluated by finding the antiderivative and evaluating on an interval with an endpoint approaching the singular point in the limit. 
For some more insight consider the improper integral of $f(x) = 1/\sqrt{x}$ as a limit of right-hand Riemann sums for a uniform partition
$$\begin{align}\int_0^1\frac{dx}{\sqrt{x}}&=\lim_{n \to \infty}\frac1{n}\sum_{k=1}^n\frac{1}{\sqrt{k/n}}\\&= \lim_{n \to \infty}\frac1{\sqrt{n}}\sum_{k=1}^n\frac{1}{\sqrt{k}}.\end{align}$$
Since
$$2(\sqrt{k+1}-\sqrt{k})=\frac{2}{\sqrt{k+1}+\sqrt{k}} \leqslant \frac{1}{\sqrt{k}} \leqslant \frac{2}{\sqrt{k}+\sqrt{k-1}}= 2(\sqrt{k}-\sqrt{k-1}),$$
we have
$$2(\sqrt{n+1} -1) \leqslant\sum_{k=1}^n\frac{1}{\sqrt{k}} \leqslant 2\sqrt{n},\\2(\sqrt{1+1/n} -1/\sqrt{n}) \leqslant \frac1{\sqrt{n}}\sum_{k=1}^n\frac{1}{\sqrt{k}} \leqslant 2,$$
and using the squeeze principle
$$\int_0^1\frac{dx}{\sqrt{x}} =\lim_{n \to \infty}\frac1{\sqrt{n}}\sum_{k=1}^n\frac{1}{\sqrt{k}}=2 .$$
We have a similar situation in your example.
Perhaps a better analogy
A change of variables can transform an improper integral into a proper integral.
Using the example $\displaystyle \int_0^1 x^{-1/2} \, dx$, change variables as $x = t^2$.
Then
$$\int_0^1 x^{-1/2} \, dx = \int_0^1 2 \, dt = 2.$$
