If the power of your test of $H_0: \mu=100$ against $H_a: \mu\ne 100$ is sufficient, you will likely reject $H_0.$ So the test has not been useless. Furthermore, it is
good statistical practice to accompany this test with a CI for $\mu.$ For example, such a CI is included in the R output for t.test
.
Also, ideally, the test would have been preceded by a power computation to find the
probability of rejection the $H_0$ is false by various amounts $\Delta.$
You are correct that the situation, in which $H_0$ does not exactly specify
the true value of $\mu,$ is commonly encountered in practice.
If the variability among contents of milk cartons is given by $\sigma=0.1$ and
we sample $n = 12$ cartons, we might get results as shown for the simulated
sample below:
set.seed(917)
x = rnorm(12, 102, .1)
t.test(x, mu = 100)
One Sample t-test
data: x
t = 66.027, df = 11, p-value = 1.193e-15
alternative hypothesis:
true mean is not equal to 100
95 percent confidence interval:
101.9421 102.0760
sample estimates:
mean of x
102.0091
In this case, $H_0$ is strongly rejected with at P-value very nearly $0.$
The 95% CI $(101.9, 102.1)$ gives a good indication that the true value
is near $\mu = 102.$
If it is the firm's intention is to overfill cartons slightly in order to avoid complaints or regulatory fines for selling
cartons that don't have the $100$g promised on the carton, then result of
the experiment and and the test and CI in R will assure them that all is well.
If the it is firm's intention to put just barely enough in each carton
to avoid underfilling the vast majority of the time, then these results might suggest a target fill amount of something like
$100.1$g or $100.2$g, depending on the particulars and pending ongoing monitoring.
Addendum: Because you ask about power computations in a Comment, I will
illustrate how one can simulate the power for a two-tailed, one-sample t test, at the 5% level, of $H_0: \mu = 100$ vs. $H_a: \mu = 101$ (specific value different from
100) when $n = 12, \sigma = 1.$ (The result can be found using a noncentral t distribution, but $n$ is too small for a good normal approximation.)
The power is about $88\%.$ That is, when $\mu_a$ differs by $\Delta = 1$ from $\mu_0 = 100,$ we have probability about $0.88$ of rejecting $H_0.$
set.seed(2020)
pv = replicate(10^5, t.test(rnorm(12, 101, 1), mu=100)$p.val)
mean(pv <= 0.05)
[1] 0.88404
The result is essentially the same for this two-tailed test if data are
$\mathsf{Norm}(99,1).$ With 100,000 samples of size $n = 12,$ one can
expect about 2-place accuracy for rejection probability.
set.seed(1234)
pv = replicate(10^5, t.test(rnorm(12, 99, 1), mu=100)$p.val)
mean(pv <= 0.05)
[1] 0.88219